1

I'm trying to do a very basic echo server using java sockets, it works perfectly locally(running both the server and client on the same computer), when I try to run the client from another computer i get the exception :

Couldn't get I/O for the connection to XXX.XXX.XX.X

XXX.XXX.XX.X being the IP of the machine on which the server is running

btw : my code for both the server and the client is roughly that of the oracle beginner tutorials : server client

EDIT : The full stacktrace I get :

java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(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 sockets.Client.main(Client.java:16)

pnuts
  • 58,317
  • 11
  • 87
  • 139
isco
  • 350
  • 4
  • 15

2 Answers2

0

As mentioned in the comments, the two used computers were hooked on two different wifi suppliers. An answer to a similar question mentions possible other reasons.

Community
  • 1
  • 1
Stefan Freitag
  • 3,578
  • 3
  • 26
  • 33
0

I get the exception

    Couldn't get I/O for the connection to XXX.XXX.XXX.XXX

That is not an exception. It is a poorly designed error message that conceals the exception. When you get an exception, don't display/print/log a meaningless error message of your own devising. Display/print/log the exception itself, and its message, and its class, and its stacktrace.

EDIT: The full stacktrace I get:

    java.net.ConnectException: Connection timed out: connect

Exactly. This is the real exception, and it almost certainly means there is a firewall preventing you from making the required connection.

user207421
  • 305,947
  • 44
  • 307
  • 483