Socket packages

O

Ole

Hi,

Is there a way to prevent Socket from assembling the packages it receives?
short explanation:
I have an application A that sends like this:
for (i0; i<4; i++)
{
MySendSocket.send(sendBuffer, count, SocketFlags.None);
}

....and a receiving application that receives like this:
while(MyReceiveSocket.connected)
{
noOfBytesReceived = MyReceiveSocket..Receive(receiveBuffer);
DoSomething..........
}

first time it receives 10 bytes but then it receives the last 30 bytes in
one package (noOfBytesReceived =30). So is there a way to force it to
receive the individual packages (the size is not necessarily the same in
each package)?

Thanks,
Ole
 
S

SirMike

Dnia Thu, 2 Nov 2006 14:34:40 +0100, Ole wrote:

Packet fragmentation is a normal thing and depends on many things.
I recommend to read about TCP/IP.
 
O

Ole

Hi again,

Some sort of method to block sender would do it, but is such a method
available?:
while(MyReceiveSocket.connected)
{
noOfBytesReceived = MyReceiveSocket..Receive(receiveBuffer);
MyReceiveSocket. BlockSender() <----- ????
DoSomething..........
}

Thanks,
Ole
 
J

Jianwei Sun

Ole said:
Hi,

Is there a way to prevent Socket from assembling the packages it receives?
short explanation:
I have an application A that sends like this:
for (i0; i<4; i++)
{
MySendSocket.send(sendBuffer, count, SocketFlags.None);
}

...and a receiving application that receives like this:
while(MyReceiveSocket.connected)
{
noOfBytesReceived = MyReceiveSocket..Receive(receiveBuffer);
DoSomething..........
}

first time it receives 10 bytes but then it receives the last 30 bytes in
one package (noOfBytesReceived =30). So is there a way to force it to
receive the individual packages (the size is not necessarily the same in
each package)?

Thanks,
Ole

The easy answer is that "No, you cannot".

You have to separate the messages by yourself. There are normally 2 ways:

1> put the number of messages size as part of the header,so you know
exactly how much you want to read.
2> use some delimiter like SOT (Start of Text), EOT(End of Text) to
separate your message.

J.W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top