server/client application fails when client closes
hi all,
I made an application wich is a server that accepts many clients, when one of those clients wants to close the connection, sends an specified string to the server and this closes the connection. That works perfectly, the problem is when the client closes the connection without sending the string, then the server knows nothing about this and keeps the usless socket open for ever.
I can't find in the literature how the server is notified when some client closes unexpectedly the connection. Any help will be just great.
Thaks, billykid.
Re: server/client application fails when client closes
One way would be to have a task on a timer to test each socket's state every so often. No idea what to test. You'd have to experiment.
Re: server/client application fails when client closes
Thanks for your reply Norm. I actually use a dedicated thread to control the socket connected to every client. I use a loop where I read the socket waiting for a data input and that loop is finished when the socket is closed for another thread of my program (checking the "Socket.isClosed()" method) or there is an error in the reading of the socket.
I thought checking the socket state in the loop, the problem is none propertie of the socket changes when the client closes unexpectedly so I can't know when that happens.
I tried setting a time out for the connection using the "Socket.setSoTimeout()" method and it works ok, but i don't want that, I want the connection to be open until the client decide to close it even if it keeps inactive for a long time.
Any idea?
Thans again, Billykid
Re: server/client application fails when client closes
Write some test code to see what you can detect about the state of the connection after the client closes it.
Re: server/client application fails when client closes
Well a while ago Inwas working on a server+client application and ran into that problem.. What I eventually ended up doing was have the client ping the server if nothing else was going on (if the text field hadn't changed and nothing was sent recently) by using an int that was designated for that purpose. however it seems Norm has a better idea and I would be quite interested to find out!