2

Possible Duplicate:
Java: How do detect a remote side socket close?

I'm writing a small program using java with Socket and ServerSocket. I have a Server and some Clients, When User(Client) close the Window, the connection between Client and Server will be closed.

My problem is on server, I can't detect that close event. Who can help me.

I can send a message from client to server to notify this event before close the connection. But if user end process from tast manager (javaw.exe), this solution will impossible.

Community
  • 1
  • 1
Võ Quang Hòa
  • 2,688
  • 3
  • 27
  • 31

1 Answers1

2

The only and only true way of finding out is to actually try to write something to the remote channel. It will throw appropriate exception if the socket is closed(similarly applies for reading, but it could return a -1 instead)

Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94