2

I am trying to make a socket connection to an ip:port and it all works correctly on one of my computers. The client first connects to the server with a socket connection to log in; after that it expects incoming connections from the server and they are successful.

But, when I tried it on another computer, the client made the first connection to log in successfuly, and then waited for incoming connections. On the server side where the connections would be initiated I got this message:

java.net.NoRouteToHostException

and the incoming connection failed.

Why would that happen? Could it be a firewall issue?

s = new Socket(id, 4446);
BufferedWriter out1 = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
BufferedReader in1 = new BufferedReader(new InputStreamReader(s.getInputStream()));

thats the 46-th line

java.net.NoRouteToHostException: No route to host: 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.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at sample_server.doComms.run(doComms.java:46)
        at java.lang.Thread.run(Unknown Source)
5
  • adding code would be meaningless, it is way too complex and it doesnt sound like a source code problem since it succeeds on one system Commented Aug 31, 2012 at 15:45
  • It's probably a network problem. Can you ping the server from the second host, and viceversa? Commented Aug 31, 2012 at 15:46
  • Show the code of how you connect the socket (not your whole code), give any host names and/or IP addresses involved and the full stacktrace. Commented Aug 31, 2012 at 15:46
  • @Evan The host names and IP addresses involved would have been the most interesting and helpful bits :) Commented Aug 31, 2012 at 16:07
  • @PhilippReichart i cant make that public phil, i tried pinging from the server though and got no response, so i m guessing its the firewall. Commented Aug 31, 2012 at 16:08

2 Answers 2

7

As stated in the API:

Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the remote host cannot be reached because of an intervening firewall, or if an intermediate router is down.

You most likely have a firewall or something blocking the connection. Try disabling one if you have one real quick, and see how that works. If it doesn't work, it's something else (the full stacktrace may help as comments on your question say).

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

2 Comments

I asked the guy if he has firewall, and he said no, i am guessing you are probably right though. Thanx
@Evan Alright, you're gonna have to TeamViewer him or something to look for his firewall for him then :P Also, +1/correct answer if this is correct (which it seems to be)
2

'No route to host' means that your host doesn't even know how to contact the target. It's a network connectivity issue. Not a firewall issue.

1 Comment

Not sure, but I believe Firewalls and Proxies might block outgoing calls, thus creating network connectivity issues.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.