Results 1 to 5 of 5
  1. #1
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default socket, automatic reconnect when server unexpectedly disconnected

    Dear All,

    I am writing client socket program..

    is there any method can I use to do automatic client
    reconnect to socket server when the server was disconnected unexpectedly?

    please help

    thanks & regards

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    You could run a timer that checks Socket.isConnected(), and if it returns false, then retry the connection.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Zack View Post
    You could run a timer that checks Socket.isConnected(), and if it returns false, then retry the connection.
    That is all possible but imagine the server keeps a lot of state. When the server notices a lost connection it might free its resources (state). Simply establishing a new connection won't do it then. I am wondering why the connection might be 'unexpectedly' get lost. Bad cables? That'd be a job for an electrician ...

    kind regards,

    Jos

  4. #4
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    well, my application does not run on LAN, but it will run on WAN, so I am just concerning when the WAN connection down.. then the client socket should know then they should keep trying to reconnect to the server

    any idea or comment?

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by newbiejava View Post
    well, my application does not run on LAN, but it will run on WAN, so I am just concerning when the WAN connection down.. then the client socket should know then they should keep trying to reconnect to the server

    any idea or comment?
    Ignoring all the state stuff I mentioned: what Zack said.

    kind regards,

    Jos

Similar Threads

  1. events on a server socket
    By newbiejava in forum New To Java
    Replies: 13
    Last Post: 08-03-2010, 08:24 AM
  2. design & generics for socket server
    By gilme in forum New To Java
    Replies: 1
    Last Post: 06-18-2010, 04:24 AM
  3. Server Socket
    By Moncleared in forum New To Java
    Replies: 1
    Last Post: 09-05-2009, 06:08 AM
  4. (Server)Socket application deploying
    By mdinant in forum Networking
    Replies: 0
    Last Post: 04-09-2008, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •