• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem of Socket Pool

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made a socket client pool from which I get a Socket con to send message to a socket server.Then when the socket server is closed,how can I test whether the connection is ok? I have tried
con.getRemoteSocketAddress();
con.isConnected();
con.isClosed();
they are ok,but in fact the socket server has been closed.How can I do?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enabling SO_KEEPALIVE will detect a broken connection, but only after a while, and at a cost. The only surefire way is to introduce a no-op test message into your application (call it "ping"), send that message to the server, and see if you get an exception thrown in your face. And even then there's a possibility that the connection will go down between pinging it and returning it to the caller -- so the calling code will have to be pepared to recover from network problems whatever you do.
- Peter
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic