I’m currently working on an asynchronous TCP-Client. I am able to send and receive messages. However, the following code is driving me crazy at the moment:
int rx = theSockId.thisSocket.EndReceive(asyn);
char[] rcvd = new char[rx + 1];
System.Text.Decoder d = System.Text.Encoding.ASCII.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, rx, rcvd, 0);
System.String szData = new System.String(rcvd);
Normally, everything works fine – but as soon as a message starts with a dollar sign ($), I only see this char.
I was searching for a long time but I couldn’t find any solution….
Receivecan complete when any data is received at the socket – not necessarily a whole “message”. You have to buffer the received data until a whole message ( as defined in your protocol ) has been received.