• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Address already in use and Socket operation on nonsocket

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi brothers and sisters,

I wanted to check whether the a server is running or not. So I wrote a client socket program to connect and check the status of the server.

I faced lot of problems that it i wanted to continuoustly check the server so i wrote the code inside a infinite while loop.

I got the above exceptions not both at once.
The address already exists exception occurred when i connected using the below code.

loop:
while(true){

tyr{
Socket s = new Socket(ip, port);
s.close();
}catch(Exception e){
continue loop;
}
}

The Socket operation on nonsocket exception occurred when i used the below command

the same while loop but I tried to connect through
new Socket.connect(SocketAddress){}

please help
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code works for me when I use a String for the IP. Exactly what are you passing as the IP (Socket takes several different arguments: InetAddress, String (host) String (ip))?
Are you certain you were not using ServerSocket? I would expect an "Address already in use" exception if you tried to bind to the same socket a server was using.
One further note, it is a good idea to put either Thread.yield or Thread.sleep calls in when writing infinite loops. That way other code can get to use the CPU once in a while.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic