This project has moved and is read-only. For the latest updates, please go here.

Not sure how to resolve this error : Socket error during read : Packet length less than zero (corrupt message)

Oct 9, 2013 at 7:58 PM
Hi Guys,

I hope you can assist. I'm the guy that posted this message on stackOverflow. I had a look the signalR, webAPI & WCF..... none of which is resonating with me and I cannot find any examples that connect to sockets. I decided to have a look at the Nito Asnc sample and it looks like its exactly what I need. I've downloaded the sample code and I've copied out the FormClientMain.cs in the SimpleClient project and placed it into my windows service app. I've also included ActionThread as I understand the existing code cannot run in a windows service. So now the windows service runs and I'm connecting successfully to the server. Then I send through some xml data to subscribe to a service on the server.

I get an error which I don't know how to resolve : Socket error during read [InvalidDataException] Packet length less than zero (corrupt message).

So I thought there was something wrong with my code, so I copied the sample client exe together with the necessary DLL's (from the Socket Demo folder) and tried to simulate my send commands and I'm getting the error message. Below is a screenshot of the calls and error. Even if I try and send an HB command I get the same error message. Normally the server would just echo HB back to my client.

Any ideas would help....much appreciated


Oct 10, 2013 at 6:07 PM
Edited Oct 10, 2013 at 6:08 PM
The SimpleClient type assumes that there is a particular TCP/IP protocol being used, and it looks like your server doesn't use that protocol.

You'll need to use ClientTcpSocket (or TcpClient or Socket) and write the protocol code yourself (including message framing and detection of dropped connections).