hey, got a question about sending data with winsock

when you send() data (less than 4kb) on a tcp socket on a slow connection (<56k) is it possible that the data will ever get split up during the transfer, and if so, how small should the packet size be so they won't split up.

e.g.
Normally if you send 1024 bytes, you'll recv 1024 bytes
by "split up" i mean, you send 1024 bytes then (in two seperate postings of FD_READ) recv 512 then recv the other 512 (with the recv buffer always at 1024)

i gotta make sure all the data is recv'd in one packet, cause the recving end, processes the first few bytes of a recv'd packet, and if it doesn't recv the whole packet that was sent, then it will attempt to process the last half of the packet

the method i'm using (if it's relevant) is:
ioctlsocket --> to find out how much data is available
allocate memory
recv --> and loop until the buffer is full or error returned
process data

basically i'm asking, if i send 3kb will ioctlsocket ever report the size of the incoming package as less than 3kb
and if so, then how small should the buffer be so that this won't happen (512b?)

(ps i know that the max you can send is around 4kb, but i'm talking bout less than that)

i think i've made it easy to understand what i'm talkin bout, but if not, i'll explain more.
thanks to anyone who can help
Posted on 2004-05-25 05:07:32 by someone
Never ever assume that message boundaries are preserved when using TCP. A TCP connection is a stream, it has no notion of seperate 'sends' or 'receives'. It does have packets but that is more IP level, in fact one of the main features of TCP is that it provides a continuous stream of data instead of seperate packets. The system also caches writes for a while so that more can be sent per packet (this is called the nagle algorithm). See also this section of the Winsock FAQ.

Thomas
Posted on 2004-05-25 05:14:33 by Thomas
hi thomas, thanks for the reply

just wondering though, i know that recv might not get the exact size of the data sent, but will ioctlsocket tell the exact size of the data sent.
otherwise how else can you tell how much data was sent, without sending the size as part of the data.

thanks
Posted on 2004-05-25 05:37:33 by someone
The maximum framesize can be gotten from the wsa data structure after winsock is started up, I hope that helped.
Posted on 2004-05-25 06:38:53 by Homer
No it may not if you are using blocking sockets.
Posted on 2004-05-25 07:16:35 by roticv
You will never know how much data was sent if you don't send it along with the data (or close the connection on one side). It's simply not possible: at any point in time, there might be arriving more data later. So how would you know you've received everything?

Thomas
Posted on 2004-05-25 08:31:50 by Thomas
hey everyone, thanks for the replies
i think thomas is right, it probably isn't possible to know whether you've received everything, unless there's something hidden in the ip packet header things, but i doubt it.

EvilHomer2k --> i think the frame size is the max size of data you can send at once which is usually around 4kb, rather than the size of each packet recv'd

roticv --> dunno if there would be a difference between blocking and non-blocking, cause it'd still be posting more than 1 FD_READ per packet

it would be good to know how other more professional network stuff does it, i know msn messenger sends the length of "bulk" messages as part of the message, and http servers have "Content-Length" and they both receive all data into a buffer until it finds a crlf (or 2).

looks like i'll have to send the length of each msg
thanks anyway
Posted on 2004-05-26 04:38:39 by someone
I was right, victor :tongue:
Posted on 2004-06-03 08:29:46 by Homer