Skip to main content

Socket connection problem:ConnectException

No replies
zeos386sx
Offline
Joined: 2004-08-06
Points: 0

hi all,
I have written a simple client/server program using the java.net.* packages. But i'm not able to connect to the server when i replace hardcode the IP address of this machine in the Socket constructor... when i use the localhost loopback IP address(127.0.0.1) things seem to work fine... i have cross checked the IP adress settings and other stuff... i have pasted the code and also the exception trace below... i have been breaking my head over this for quite some time now... any help would be useful...
and there are no firewalls on this machine where i'm running these two programs.
and also i first start the server in one console window and then start the client in another console...
thanks in advance for any help...
cheers..!!
here goes the CODE:

Client:
import java.net.*;
class test2
{
public static void main(String[] args)
{
try
{
Socket s = new Socket("IP.ADD.OF.MC",7777);
System.out.println(s);

}catch(Exception e){e.printStackTrace();}

}
}

Server:
import java.net.*;
class test1
{
public static void main(String[] args)
{
try
{
ServerSocket ss = new ServerSocket(7777);
Socket s = ss.accept();
System.out.println(s);
}catch(Exception e){e.printStackTrace();}
}
}
Exception on Client Console:
\programs>java test2
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.(Unknown Source)
at java.net.Socket.(Unknown Source)
at test2.main(test2.java:8)