Method isConnected()........please help!!
I am using the Socket class to make client-server connection:Can somebody please explain me the following:why after closing a connection with socket.close() return both methods socket.isConnected(),socket.isClosed() true? Why is the connection still
[299 byte] By [
aimuellera] at [2007-10-2 10:50:53]

isConnected() returns true if the socket is connected or has been connected in the past.
I think isConnected() and isClosed() are rarely useful. It is better to write your application so you don't need them. Connect the socket to a server - then you know it is connected. When you are done communicating close it (usually in a finally clause). Then you know it is closed.
(Ok, perhaps sometimes servers with multiple clients, maybe asynchronous connect? But usually no.)
The only way to do that is to try to use it. If you get a SocketException or EOFException the connection is closed.Socket.isConnected() only tells you about what you have done to your own Socket at this end, not about the state of the connection.
ejpa at 2007-7-13 3:09:17 >
