Advertisement

recv() question.

Started by July 06, 2006 05:06 PM
6 comments, last by Unconquerable 18 years, 7 months ago
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.
Advertisement
How do i do that?
Well, how are you doing your sends and receives now?
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.
My send() and recv()
     nret = send(theClient,buffer,strlen(buffer), 0);	 

nret = recv(theSocket,buffer,256, 0);
Advertisement
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.
Quote:
Original post by SiCrane
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.


That worked, thank you. =D

This topic is closed to new replies.

Advertisement