How can I grasp the concept of C sockets?

1    07 Jul 2015 17:53 by u/somedudeperson

I'm currently following Beej's guide to Network Programming and my goal is to get good enough so I can program any simple networking app. The problem is I don't really understand how I should study it. Should I memorize the structs and how they are built? Why do the send\recv system calls return the number of bytes sent? Do you have any recommendations or ELI5s about it? I'll be very grateful

3 comments

0

I'd say just use it, you will get to know what you need over time. Just write a chat progam or something like that.

The number of bytes are returned so you can check that a) everything you need has been transfered, because that is not always the case, and checking is always better than assuming, and b) so you can easily loop over it byte for byte.

0

Wax on, wax off, wax on, wax off.

You can only memorize it by applying it again and again. Just be aware that the entire interface is different in say, C# or Java. You're learning C specific networking code here.

0

I'd say its good thing to learn the OS calls and the basics behind socket programming, but for any practical purposed maybe look into zeroMQ I really liked using it so far. It has libraries for all the major languages and you don't have to bog yourself down with how many bytes were sent you.