Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i check if connection is alive ?  RSS feed

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
im using simple Socket(hostname, port); to connect to my email server
is there any way to check if after i connected to the server the connection still alive ?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the only reliable way to know is to try it now and then. Some servers expect a heartbeat from clients ... if they don't call in every once in a while the server assumes the client is dead and ends a session. Some clients ping the server now and then to see if it's still alive.

Another approach is to try the connection only when you need it. If it fails with some particular error, reconnect and try again. Then you don't really care if it's failed and been dead for the last 15 minutes, only when you really want to use it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!