A good example of what to watch out for is demonstrated by your friendly neghborhood telnet client. If you type slow enough each keypress is sent through a single char at a time. Try pressing tab or even backspace or arrow keys. Depending on how you parse the data on the receiving end this can cause lot's of problems.
One thing I have done in the past (and still use) in a text based MUD is a receiving buffer that fills up until a newline character is found. Once a newline is found, that portion of the buffer is parsed to find any special characters or escape sequences and interpreted accordingly. The resulting string is pushed onto a queue of command lines to be parsed etc...
Now, if I ever received a '\0' in the middle of a string that would be an error for me since only text should be passed back and forth for me and I drop their connection because something went wrong. I don't know what kind of information you are expecting from the end user but this is something to consider as well.
Take for example the code below:
Uint32 Recv( TCPsocket sock, std::string &buffer ){ Uint32 temp,total; char data[MAX_LEN]; total = 0; while( (temp=SDLNet_TCP_Recv(sock,&data,MAX_LEN)) != 0 ) { buffer += std::string(data,temp); total += temp; // if the sender is spamming, possibly continuing from a previous send if ( buffer.size() >= MAX_BUFFER_SIZE ) // kill the connection and move on } return total;}
That will continue to fill buffer until there is nothing left to receive or you go over a pre-determined amount. It is still up to you to parse buffer according to what you are expecting be there NULL's in the middle or not. I can't stress enough though how important it is to pay attention to how much is received and check it against how much you have parsed. This will help you find potential problems that can be very difficult to track down especially once you move on to higher level things that rely on the socket code to be solid.