Reputation:
I want to run a client/server application that is built in Java using socket connection. If I run both the server and the client program in same machine, the client and server communicate each other as expected. But on the other hand, if run the client program on some other system, I get an exception
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
Could anyone help me solve this problem?
Upvotes: 0
Views: 1682
Reputation: 53687
the main problem what i think is that you have to open the port. The server and clients are communicating using the same port. when u r using the same machine in that case all the ports are open for it self. but to connect with separate systems u have to open the port. actually this is the job of the administrator to open the port.
Thanks Sunil Kumar Sahoo
Upvotes: 0
Reputation: 533820
It sounds like you have a firewall (Windows and Linux have these on by default) on your server and you need to allow other machines to connect on the port you are using.
Upvotes: 0
Reputation: 2435
In addition to what Bhushan said, check that it isn't being blocked by a firewall. In particular, Windows XP's built in firewall often catches me out.
You can also test your TCP connection (I'm assuming you're using TCP) by telnet'n from the client to the server, i.e.
client.host] telnet ip.of.server port.of.application
and see what response you get. If you get anything other than a timeout, then you're using the wrong address/port values in your Socket object.
Upvotes: 4
Reputation: 10987
How you created the Socket object in client? Can we see the code of server and client both? May be you are using localhost while creating the client Socket object. Instead of localhost use the ip address or the hostname of the machine which is running the Server. Also check if both the machines are on same network and can see each other.
Upvotes: 1