TCP Client Side Exception

basil365 used Ask the Experts™
Hi guys,

We have a Windows Service hosting a TCP server which sends updates out to clients every few minutes.

The vast majority of the time there are no issues on either side. However, recently every so often we've started seeing the following exceptions:

SerializationException: The input stream is not a valid binary format. The starting contents (in bytes) are: ...

SocketException (0x80004005): An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full

I am using Message Framing to send the size of the data, which I thought would prevent the first exception from happening.

I've no idea about the second exception. Appears to be completely random. It doesn't affect the server, only the client. After it appears the client that received the error stops receiving messages.

Any suggestions would be much appreciated.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Aaron JabamaniTechnical Architect

From the error looks like the client input buffer is overflowing.  The server is sending more data at some point of time , the client can handle.  Either server should slow down, or client should process the incoming data as soon as possible.


On the client side I am using an AsyncCallback to receive messages as they are sent:

socket.BeginReceive(state.buffer, 0, //offset
                                 state.buffer.Length, //how much data can be read
                                 SocketFlags.None, new AsyncCallback(OnReceive), state);

Is there a better way of doing this?

On the server side objects are getting updated on seperate threads and sent to clients as soon as the updates are completed.

Is it necessary to have a queuing system to send these updates sequentially?
Technical Architect
Have a queue at client side and store the data as soon as you get from server instead of processing them straight away. You can have a Threadpool to process the messages from the client queue.


Thanks for the advice, I will implement this and see if the issue persists.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial