aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes urgent tcp server problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "urgent tcp server problem" Watch "urgent tcp server problem" New topic
Author

urgent tcp server problem

dhiraj dhiraj
Greenhorn

Joined: Jan 18, 2003
Posts: 3
I have a serious problem. My tcp server is not able to detect when client is shut down or is crashed. Due to which the server is under assumption that the client is still connected and it does not update the data base.
ex: I have my server running and when one of the client is shut down or there is power cut then the server is not able to detect this.
can some one please help me
thanks
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

My tcp server is not able to detect when client is shut down or is crashed.

One (crude) solution is a pinging thread that runs on client telling the server "I am still alive".
Eugene.
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
the client socket will be null and a nullpointer exception will be thrown when the client crashes..
check for this.
Regds
Lupo


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
dhiraj dhiraj
Greenhorn

Joined: Jan 18, 2003
Posts: 3
Thanks Eugene Kononov,
I have put pinging as last option. I still can't belive that there is no better solution. But i must say this is a serious bug in Java and how come Sun has not done any thing regarding this.

Hello gautham kasinath,
What u have said is perfectly true when client is closed with normal termination but when any unusual things happen(power cut, system shut down, cable unplugged) then even if on the server a thread is dedicated to listen the client it will never be notified about the status of client.
thanks
[ January 20, 2003: Message edited by: dhiraj dhiraj ]
[ January 20, 2003: Message edited by: dhiraj dhiraj ]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by dhiraj dhiraj:
I have put pinging as last option. I still can't belive that there is no better solution. But i must say this is a serious bug in Java and how come Sun has not done any thing regarding this.
A bug in Java, or the nature of networking? How would you propose to do the things you want to do without sending a regular ping of some sort over the network, and do you really want to incur that overhead in the all the applications that don't need this functionality at all?
In any case, precisely for this problem there's a TCP/IP extension called "keepalive", which essentially does the pinging for you at the protocol level. You can enable keepalive on a socket by calling setKeepAlive(true). My understanding is that this should eventually give you a SocketException if the connection has died. If that doesn't work for you, well, you won't lose an awful lot by some reasonably intelligent pinging.
HTH
- Peter
[ January 23, 2003: Message edited by: Peter den Haan ]
Tristan Bean
Greenhorn

Joined: Jan 28, 2003
Posts: 1
I use Object Stream in a little chat app and i always detect when the client disconnects. The server is constatly reading and if it reads null for a client it broadcast the "user left" or what ever

eg
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: urgent tcp server problem
 
Similar Threads
Weblogic 10.3.4 timeout on shut down
problem in login page
Stopping DataServer using socket connection
How do I listen a client shutdown
NX: (Contractors) server shutdown and file close