Question

I need to get the whole message(response), but socket.ReceiveBytes(); returns just part of the message. I tried to loop it but it fails on timeout when no bytes to receive.

List<byte> lb = new List<byte>();
byte[] receivedMsg = socket.ReceiveBytes();   
while (receivedMsg.Length > 0)
{         
     lb.AddRange(receivedMsg);
     receivedMsg = socket.ReceiveBytes();
}

So, how I can check if there are byte to read? How I can read the whole message?

Was it helpful?

Solution

Since its a Chilkat implementation, you should probably contact the developer. But I found this that could help: http://www.cknotes.com/?p=302

Ultimately, you need to know how much to read from the socket to constitute a whole message. For example, if the overlying protocol is a portmapper, then you know that you are expecting messsages in the format that the RFC specifies (http://tools.ietf.org/html/rfc1833.)

If you are rolling your own protocol over a socket connection, then use the method in the Chilkat blog post about putting the size of the total message in the first 4 bytes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top