Jump to content
  • Advertisement
Sign in to follow this  

why create a socket in SDLnet

This topic is 4232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have a question about sdl_net. If I have a server and a client (the same client all the time). Is it safe to accept the connection from the client by calling SDLNet_TCP_Accept and using the teurned sock to receive data multiple times( without the the need to accept connecton everytime). The same applies for the client, I dont want to open connection everytime, I would like to send data to the sock that I opened (and sent data earlier).... I tried it ,it worked.. but the below comment from the sdl_net website tutorial confuses me // send a hello over sock //TCPsocket sock; int len,result; char *msg="Hello!"; len=strlen(msg)+1; // add one for the terminating NULL result=SDLNet_TCP_Send(sock,msg,len); if(result<len) { printf("SDLNet_TCP_Send: %s\n", SDLNet_GetError()); // It may be good to disconnect sock because it is likely invalid now. } Why is it invalide, what if I want to reuse it to send data again?! Thanks a lot for the help

Share this post


Link to post
Share on other sites
Advertisement
The comment "It may be good to disconnect sock because it is likely invalid now." is inside of the error checking code that only gets run when the number of bytes sent is less than the number of bytes you wanted to send. In that case, you experienced some sort of error, so your socket is probably no longer valid. In the general case, though, it should be fine to re-use your socket.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!