TCP Sockets and disconnects

Monkey Forums/Monkey Programming/TCP Sockets and disconnects

benmc(Posted 2013) [#1]
I don't see any way to unbind or disconnect servers or clients in the Socket Class.

I'm having issues where if someone is disconnected from the server in any way, they cannot reconnect. I can't seem to restart the server or tell if the client has been disconnected as the server.

Does anyone know how to detect if a client has disconnected, or how to unbind the server from the port so it can be restarted or stopped if needed? Just setting the server to Null and creating a new one doesn't seem to work - it seems to stay bound until the app is completely closed.


Xaron(Posted 2013) [#2]
How to detect if a client has disconnected should be easy. Just ping it here and there and if you don't get a response anymore, it's gone.


benmc(Posted 2013) [#3]
I don't think you can ping the client as the server. You can technically kill the connection after inactivity, but I want to give the player the option to stop the server, or cancel the operation while waiting for an opponent to connect in case there's a problem. So a Disconnect for clients or a ShutDown for the server would be really helpful.


Xaron(Posted 2013) [#4]
Well you can send a "alive" request to the client. When the client does not respond, kick it. I still don't understand the need for a server shutdown. Maybe I simply don't understand what you want to achieve. Is it something like p2p? If so, you'll run into many more problems because then you need NAT punchthrough which isn't necessary for a master (authoritive) server and many clients.


benmc(Posted 2013) [#5]
I'm making a simple 2-player local wifi game.

It works like most multiplayer mobile games.

You choose whether to Create or Join a game.

If you choose to Create a game, it sits and "waits" until the other local wifi client Joins the game. (Which is also why I have implemented a way to get the local IP address that you can give to the other player so they can connect to your server)

Well, if that person can't get the game working, or you just change your mind, instead of closing the entire game, and on some devices, killing the process, I would like the ability to click cancel, unbind the server, and return to the game.

I don't see a command to check if the connection is alive or not. I see an IsConnected, so maybe that's what I need to check from time to time.


Xaron(Posted 2013) [#6]
Ah well now I get it. What do you do if both players are behind the same router having local ip so you can't connect directly?

Maybe for p2p games it would be a good idea to make a module for stuff like Pubnub or Photon network where it's very easy to do something like this.