You read from a socket, into a buffer you malloc() of size 256 bytes. You only receive 250 bytes, but you know you are to receive 256. What is happening, and what do you do about it? In general, how do you know when you have finished reading from this socket?
Expert Answer
Sockets have nothing built in mechanism to say whether a socket has been read completely or not. If a client is reading the socket and expecting that recv function will return 0 or eof when the socket is read completely, then nothing of this sort happens. The recv call will block untill more data is there to read. It will return 0 only when connection gets closed and not otherwise.
An easy way to mark the end of the message , a special character or string can be used to mark the end of the message. So once such a marker is received , it is understood that complete message has been receibved.