 <p>you need to declare inbuffer at least as many bytes as the size of MAX_PACKET char * inbuffer = new char[MAX_PACKET];</p> <p>and place before each recv() memset(inbuffer,0,MAX_BUFFER); to zero out the buffer so you don't mistakenly see the tail end of a previous packet in the scenario you received two packets where the 2nd is shorter than the 1st.</p> <p>if your incoming packet has no unique termination byte ie '\r' you need to add int recvbytes ; recvbytes =new recv(...) since recv returns the number of bytes received on the wire</p>