Valhalla Legends Forums Archive | Java Programming | Detecting remote socket disconnects?

AuthorMessageTime
JoeTheOdd
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?
December 5, 2005, 2:44 AM
The-FooL
Depends on how you implement your sockets.
December 5, 2005, 4:22 AM
JoeTheOdd
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.
December 5, 2005, 1:05 PM
The-FooL
[code]
public SocketAddress getRemoteSocketAddress()

    Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
[/code]
Socket
December 5, 2005, 8:26 PM
JoeTheOdd
Pssh. You rock. =)

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

EDIT -
[quote]a SocketAddress reprensenting the remote endpoint of this socket, or null if it is not connected yet.[/quote]

Yeah, it only returns null if it hasn't been connected yet. Same as isConnected().
December 5, 2005, 11:34 PM
JoeTheOdd
I've taken iago's suggestion of sending a keepalive packet, and if it errors on sending you've been disconnected.
December 5, 2005, 11:45 PM
Quarantine
YOU LIAR I SUGGESTED THAT LIKE 4 DAYS AGO OMG.
December 6, 2005, 2:20 AM
JoeTheOdd
iago suggested it five. G_G.
December 6, 2005, 1:04 PM

Search