java - How to make client socket wait for server socket -


if client socket opens before server socket, java generate connectionexception. have check whether server available , keep waiting before executing

socketchannel.open(hostname, port)

in client thread. i've found related api:

inetaddress.getbyname(hostname).isreachable()

however, still can't tell whether socket on specific port open. think problem should common didn't useful information google , other places.

boolean scanning=true; while(scanning) {     try     {         socketchannel.open(hostname, port);         scanning=false;     }     catch(connectionexception e)     {         system.out.println("connect failed, waiting , trying again");         try         {             thread.sleep(2000);//2 seconds         }         catch(interruptedexception ie){             ie.printstacktrace();         }     }  } 

this code sonics comment


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -