• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

TCP socket programming in C

zerocool1

Diamond Member
Umm , I'm trying to figure out how much data a server app is going to send me/to send to it. Is there any way to figure that out other than by trial and error?
 
Eh?

TCP is just a comm protocol. There's no specification for data size messages. If you're using HTTP it has it's own header format as does FTP. If you're just sending data back and forth between two of your own apps, invent your own protocol.
 
Any decent book on socket programming will tell you that you can't predict the size of any one packet.

If you want to send 1024 bytes the software stack may accept it in one call, or make you send it as 256, 768 or as 1000, 24, or . . .

For both sending and receiving you generally need to loop and send / get as much as the software stack accepts / provides until you're done.

As AntiEverything noted it's up to the protocol layered on top of TCP, like HTTP or FTP or POP3, to determine when you are done with a message.
 
I was going to suggest you look at something simple like netcat's source, but after having looked at it myself I think it might scare you away from socket programming...
 
Back
Top