Re: data packet split problem in socket networking

Tech-Archive recommends: Speed Up your PC by fixing your registry



If you are using TCP, be aware that one call to send() may be perceived as multiple different calls to recv() on the other end (or vice versa - multiple send() calls can be received in one recv() call). There is also the possibility that you will get a partial message in a call to recv(), requiring you to make additional calls.

TCP guarantees that your data will arrive in the same order.

UDP will guarantee that you only receive whole messages, but it does not guarantee reliability nor does it guarantee sequencing. I assume that you are probably using TCP, since you spoke of messages appearing to be split.

--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
"Vic" <Vic@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:DC75258F-2EB9-4929-A9D7-A86A16650827@xxxxxxxxxxxxxxxx
Hi Guru,

I am new with socket applications, and now trying to build a client-server
application to use socket for data transportation.
I am using VC6 on PC, included ws2_32.lib in my project.

I found that *sometimes* the packet received at the client side is split and
MAYBE *re-organized* (I am sure the packets were often split, but need to
confirm if the packets are re-organized or not).
I have several data sources, e.g., each data source is a file, to be sent to
the SAME client.
One way for the implementation is: for each data source, we build a socket,
and send its data to the client at a unique port.
This will make the different data sources independent, but needs many
connections.

Another way is just to use one Server-Client connection, and the server
sends the data from each source one by one.
Each packet of data has a header, which indicates to which data source this
packet belongs, e.g., SourceID.
Hopefully, the server will receive the packets of data in exactly the same
packet as the client sent it.
But if the packets are split and re-organized, special process will be
needed to separate the data in the receiver buffer.

I have following questions and hope you can give me the answers:

1. The socket split can be avoided or not? Say, if we use smaller packet
size, will we be sure that the socket will not be split?
2. What should be the suitable packet size be set?
3. Is it for sure that if a packet is split, the data will be sent in the
succeeded packet? We should be sure that the data should be received in order.
4. Will the socket packet be split and re-organized? For example, if the
previous packet is split, will the next socket packet contain the rest part
of the previous packet plus some of the data from the next packet?
If it is true, the header info may not be at the beginning of the packet.
5. Generally, where in a packet will the split happen? Are there any rules
for this?
6. The SourceID takes 2 bytes in our case, is it possible that the split
happens exactly between the the 2 bytes of SourceID, say the 1st byte of
SourceD is in one packet, and the 2nd byte of SourceID is sent in the another
packet (hope it is in the next packet)? If this happens, it will be even more
difficult for me to process the received data.

Please tell me the answer or tell me the souce where i can find more info.

Thanks in advance!

Victor

.



Relevant Pages