File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Address already in use and Socket operation on nonsocket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Address already in use and Socket operation on nonsocket" Watch "Address already in use and Socket operation on nonsocket" New topic
Author

Address already in use and Socket operation on nonsocket

Piradharsan Navaratnam
Greenhorn

Joined: May 15, 2007
Posts: 14
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
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Address already in use and Socket operation on nonsocket
 
Similar Threads
Ports in Use
Socket Exception : Operation Time out
Ports in Use
Socket Exception : Operation Time out
Client Failed to connect, how do I attempt a reconnect?