
recv() question.
Hi. I'm playing around with Winsock, and i have a basic server and a basic client. When the client connects to the server, you can type something in to the server to send to the client. That works fine, but on the client, after it prints what the server sent, it prints a little line of jibberish characters. To see what i mean:
Thanks.

You probably aren't sending and/or receiving the terminating null for the string.
When you send, send the string plus the character '0' at the end.
A string in C is an array of characters ended by this character.
A string in C is an array of characters ended by this character.
My send() and recv()
nret = send(theClient,buffer,strlen(buffer), 0);
nret = recv(theSocket,buffer,256, 0);
strlen() doesn't include the terminating null when counting the characters in the string. Solution: add one to result of strlen() to account for the terminating null.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement