This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent tcp server problem  RSS feed

 
dhiraj dhiraj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the client socket will be null and a nullpointer exception will be thrown when the client crashes..
check for this.
Regds
Lupo
 
dhiraj dhiraj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!