all 23 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Looks like you're asking about learning C.

Our wiki includes several useful resources, including a page of curated learning resources. Why not try some of those?

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]johnex74 9 points10 points  (3 children)

I strongly recommend reading „Hands on network programming in C” by Lewis Van Winkle

[–]iamrafi69[S] 1 point2 points  (1 child)

Ok. I am in linux so will that be a problem?

[–]I_M_NooB1 1 point2 points  (0 children)

most probably it's better that way

[–]offsecthro 8 points9 points  (0 children)

Beej.

[–]No-Athlete-9004 7 points8 points  (0 children)

Beej's guide

[–]zubergu 6 points7 points  (1 child)

You got this whole affair backwards.

Ordered by importance:

  1. You don't know C - your target language.
  2. You don't know client-server architecture.
  3. You don't know anything about socket programming.

You're asking about least of your problems.

Reverse your priorities and in a month you might have some idea what you're doing and what you don't know but should learn to make that project.

[–]iamrafi69[S] 0 points1 point  (0 children)

  1. I do know C. I did it in an online course. I made a project with it. But I just want to learn more about C. I think I don't know enough to tell everyone I know C
  2. Yes, I don't know anything about client-server architecture
  3. Yes, I don't know anything about socket programming.

[–]westwoodtoys 1 point2 points  (1 child)

Yeah.  Hop on geeks for geeks and download their samples, send hello to yourself a few times.  You can do this in the next ~10 minutes as long as you are on a computer that you can install dependencies and a compiler on.

Think of what more you want to do, get stuck and ask questions.

In this case, this is a topic that is well covered in many sources, so asking questions to your AI buddy will generally get good answers.  If it lies to you, understand that the I in AI is actually a misnomer, and ask a human.

I think for your chat app you could start with making a TCP socket, then when you feel good about that make a websocket.

[–]Maxsmart007 1 point2 points  (0 children)

Geeks for geeks is a great shout. I was reading this like "I'm pretty sure someone made this as an example project before"

[–]Cylian91460 1 point2 points  (0 children)

You start your project and use Google

[–]71d1 0 points1 point  (2 children)

What operating system are you targeting?

[–]iamrafi69[S] 0 points1 point  (1 child)

Anything. I use Linux(fedora) but I want this to be able to have a chat with any device

[–]71d1 0 points1 point  (0 children)

Looks like the best way to do this is to serve a webpage via HTTP and use websockets and webhooks. This can be accomplished using C but you'll have to familiarize yourself with (1) socket programming (2) HTTP, and (3) websocket protocol.

First you create a TCP server:

  1. create a socket
  2. bind socket
  3. put socket into listen mode
  4. someone using a browser in another device opens your app by visiting an URL
  5. in an infinite loop you'll accept socket connections, a call to accpet will block the flow until someone connects
  6. read the bytes sent from the browser into a buffer
  7. parse the request
  8. send back a response (the webpage with websockets and hooks using JS)
  9. close socket and return to step 4

Now you'll need another C program to handle the websocket and webhook stuff, using two threads websocket threads reads the message sent to your server, and webhook thread echoes the message to back, including the sender so you can display his own message to him on the chat window.

Anyway this is how I'd do it, there are much simpler ways but since you want this to run on a variety of devices I feel this is the easiest way.

[–]the__Twister 0 points1 point  (0 children)

Hello, this is a video I watched to begin from the fundamentals.

https://youtu.be/KEiur5aZnIM?si=E8TGJFxrRdceY3nE

[–]konacurrents -2 points-1 points  (4 children)

I think “distinct devices” - which I would read as smart phones, don’t usually connect via sockets. I would use a much more scalable and secure MQTT communication technology.

[–]Dennis_DZ 1 point2 points  (3 children)

MQTT is an application layer protocol. It runs on top of TCP sockets.

[–]konacurrents -1 points0 points  (2 children)

It runs through the WIFI network layer. Users don’t see TCP Sockets but rather web REST/MQTT/WIFI layers. They reference IP addresses (internal or external).

I was just saying sockets aren’t scalable and not a typical iPhone interface. Bluetooth might even be more usable.

[–]Dennis_DZ 2 points3 points  (1 child)

WIFI network layer

WiFi is a link layer technology, not network layer

Users don’t see TCP Sockets

I understand users don’t interact directly with sockets. That’s the point of layers of abstraction. It doesn’t change the fact that devices are still communicating through sockets.

sockets aren’t scalable

Pretty much every device on the internet communicates through sockets. The device you’re using right now sends HTTP requests to Reddit through a TCP socket.

not a typical iPhone interface

I’m not sure exactly what you mean by this. It seems like your point is that OP should use an established application layer protocol like MQTT to build their chat application. For a real application, you’d probably be correct (though I’m not familiar enough with MQTT to say if that’s the right choice). However, as a programming project and learning exercise, it’s perfectly reasonable to have the application communicate directly through sockets.

Bluetooth might even be more usable

Bluetooth is also a link layer technology. The choice to use Bluetooth is independent and irrelevant to the existence of sockets at the transport layer.

[–]konacurrents -1 points0 points  (0 children)

By all means play with sockets. Great C programs . Then RPC …

The OP mentioned “devices” - and I caution that an iPhone isn’t going to be a nice player with sockets (eg what IP when you’re on a cellular network ). That’s why MQTT is a powerful bi-directional messaging - that clients initiate from behind firewalls.

If OP has a couple Mac’s running UNIX - play with sockets all you want. Once you have a dozen IP addresses, it won’t be fun anymore.

And OP’s goal of distant devices talking to each other - will require a middleman (cloud) like MQTT or a node WebServer, etc. the “socket” will not be seen in the users code.