• Welcome to Valhalla Legends Archive.
 

Detecting remote socket disconnects?

Started by Joe[x86], December 04, 2005, 08:44 PM

Previous topic - Next topic

Joe[x86]

I want to be able to set a boolean (bConnected) to true if the socket is disconnected. I asume this would be done easiest in my loop to receive data, but any other suggested places are also welcomed.

I don't know of any way to detect if the remote end of the socket has created a disconnect. I want to distroy finished threads (defined by the socket being closed), but its kinda hard to do if I don't know when its finished.

Does anyone know how to go about doing this?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

The-FooL

Depends on how you implement your sockets.

Joe[x86]

I've got a socket listening, and constantly accepting connections, which are forked to a new handling class, with the socket passed in its constructor. What I want to do is loop through the classes (that's easy), and check if its still connected, and if not, set it = null.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

The-FooL


public SocketAddress getRemoteSocketAddress()

    Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

Socket

Joe[x86]

#4
Pssh. You rock. =)

EDIT -
Eh, it still doesn't work. =(

EDIT -
Quotea SocketAddress reprensenting the remote endpoint of this socket, or null if it is not connected yet.

Yeah, it only returns null if it hasn't been connected yet. Same as isConnected().
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Joe[x86]

I've taken iago's suggestion of sending a keepalive packet, and if it errors on sending you've been disconnected.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Warrior

YOU LIAR I SUGGESTED THAT LIKE 4 DAYS AGO OMG.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.