0

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?

1
  • 1
    can we see the code you use to create the ServerSocket? Commented Apr 22, 2009 at 9:35

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

I got answer Sir, Thanks for reply
0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.