TCP socket programming in C

zerocool1

Diamond Member
Jun 7, 2002
4,486
1
81
femaven.blogspot.com
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?
 

AntiEverything

Senior member
Aug 5, 2004
939
0
0
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.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
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.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
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...