SDL_net: What must be done on TCP_Recv/Send errors?

When either SDLNet_TCP_Recv() or SDLNet_TCP_Send() fail, the docs mention:
“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.
}”

I know the socket is invalid, since it crashes on a
SDLNet_TCP_Close(), but what is meant by ‘It may be good to disconnect
sock because it is likely invalid now’ ?

AFAICT, there is no way to know if that socket is invalid once we get
a error on either send/recv calls.
I tried to do a SDLNet_DelSocket(), but since that socket is invalid,
that call fails also.

What I ended up doing was just set sock to NULL, and that turns out
OK, but I am not sure this is at all a correct way to handle this.

Anyone know the correct way to “disconnect sock” ?

Thanks for your help.

sorry vaugly bending the topic again but i will soon be thinking about
thinking
about adding network capabilities to a project and i have never down anything
network from my code so am worried i wont get it perfect enough so is
there any
good examples of its use or how to best use it?

i will be wanting to send and recieve between 2 players their mouse coordiante
as real time as possible, along with a small amount of other data.

I am not sure it it would make more sence to have an independent server rather
than having 1 of the clients acting as server. so if a disconnect occurs the
server can still hold the game which could be in a pause state until
the player
finds thier connection.

any pointers for me most welcomed, thanks.

Hey,

I’m still dealing with an unrelated networking bug of my own, but I’ve put together some good stuff for starting networking code. I was going to test it further and pimp it with more comments, but if you’d like what I have so far, I’ll send it to you. It builds from NET2 (which I definitely recommend), adding in some simple packet-forming functions (taken from Beej’s tutorial) and simpler access functions to these. It handles incomplete packets and multiple packets in the same buffer, as well (these could use more testing). The stuff I have is a build of NET2 that includes Fast Events and those packet functions in a single dll.

Using this stuff, sending mouse coordinate data is as easy as sendZHLL(socket, P_MOUSECOORD, mx, my), and receiving it is like:
receiveH(type);
if(type == P_MOUSECOORD){
receiveL(mx);
receiveL(my);
}

I implemented a client-server thing for my game, where one player is the server. The server handles everything while the clients just send info to the server. I have host-recovery in that the clients send their IP addresses to the server, who relays the info back to each client. If the server disconnects, the clients decide (based on ping) which client becomes the new host and then they connect to it.

Jonny D> Date: Sat, 19 Apr 2008 11:19:21 +0100

From: neil at cloudsprinter.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_net: What must be done on TCP_Recv/Send errors?

sorry vaugly bending the topic again but i will soon be thinking about
thinking
about adding network capabilities to a project and i have never down anything
network from my code so am worried i wont get it perfect enough so is
there any
good examples of its use or how to best use it?

i will be wanting to send and recieve between 2 players their mouse coordiante
as real time as possible, along with a small amount of other data.

I am not sure it it would make more sence to have an independent server rather
than having 1 of the clients acting as server. so if a disconnect occurs the
server can still hold the game which could be in a pause state until
the player
finds thier connection.

any pointers for me most welcomed, thanks.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Going green? See the top 12 foods to eat organic.
http://green.msn.com/galleries/photos/photos.aspx?gid=164&ocid=T003MSN51N1653A

Hey, if anyone else is interested, I posted that library on my site as
"Jnet". It’s just a repackaging of Fast Events, NET2, and Beej’s packing
functions, so you only need one dll. I also included a
Packets_Example.h that leads you through defining packets. Tell me how
it works for you!

http://pubpages.unh.edu/~jmb97/SDL.html

Jonny DFrom: grimfang4@hotmail.com
To: sdl at lists.libsdl.org
Date: Sat, 19 Apr 2008 09:12:02 -0400
Subject: Re: [SDL] SDL_net: What must be done on TCP_Recv/Send errors?

Hey,

I’m still dealing with an unrelated networking bug of my own, but I’ve put together some good stuff for starting networking code. I was going to test it further and pimp it with more comments, but if you’d like what I have so far, I’ll send it to you. It builds from NET2 (which I definitely recommend), adding in some simple packet-forming functions (taken from Beej’s tutorial) and simpler access functions to these. It handles incomplete packets and multiple packets in the same buffer, as well (these could use more testing). The stuff I have is a build of NET2 that includes Fast Events and those packet functions in a single dll.

Using this stuff, sending mouse coordinate data is as easy as sendZHLL(socket, P_MOUSECOORD, mx, my), and receiving it is like:
receiveH(type);
if(type == P_MOUSECOORD){
receiveL(mx);
receiveL(my);
}

I implemented a client-server thing for my game, where one player is the server. The server handles everything while the clients just send info to the server. I have host-recovery in that the clients send their IP addresses to the server, who relays the info back to each client. If the server disconnects, the clients decide (based on ping) which client becomes the new host and then they connect to it.

Jonny D

Date: Sat, 19 Apr 2008 11:19:21 +0100
From: neil at cloudsprinter.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_net: What must be done on TCP_Recv/Send errors?

sorry vaugly bending the topic again but i will soon be thinking about
thinking
about adding network capabilities to a project and i have never down anything
network from my code so am worried i wont get it perfect enough so is
there any
good examples of its use or how to best use it?

i will be wanting to send and recieve between 2 players their mouse coordiante
as real time as possible, along with a small amount of other data.

I am not sure it it would make more sence to have an independent server rather
than having 1 of the clients acting as server. so if a disconnect occurs the
server can still hold the game which could be in a pause state until
the player
finds thier connection.

any pointers for me most welcomed, thanks.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Going green? See the top 12 foods to eat organic.


Pack up or back up?use SkyDrive to transfer files or keep extra copies. Learn how.
http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008