0

I've created a simple chat program which communicates using sockets. Everything works fine when I'm running it on localhost. However, the problems occur when I try to link the client and server programs using my IP.

http://www.canyouseeme.org/ can connect to my server on port 9999 so I know that the server is fine and the port is open. However, my client can't connect.

The error log...

java.net.ConnectException: Connection refused: 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 Client.connect(Client.java:129)
at Client.main(Client.java:47)

Does anybody have any idea what might be causing this? Thanks in advance.

Edit: Links to the full source code:

http://pastebin.com/2XftHtn9

  • 1
    Do you have a proxy in place, and if so, did you properly configure your Java application? – home Mar 04 '12 at 13:45
  • Can you show more code and details? - for example, we can't actually tell whether you are using the right port and IP. – DNA Mar 04 '12 at 13:47
  • send your complete code, re-check `ip` and `port`. also it's better if you use `SocketFactory.createSocket` approach. – Sam Mar 04 '12 at 13:49

2 Answers2

2

Have a look at the answers to: java.net.ConnectException: Connection refused

My first suspicion however would be a firewall issue.....

Community
  • 1
  • 1
mikera
  • 105,238
  • 25
  • 256
  • 415
  • Thanks, but I've seen that link about 4 times while searching for how to fix the problem... the code there uses localhost instead of a proper IP, which is where my problem occurs. I'll recheck my firewall settings for outgoing TCP requests. –  Mar 04 '12 at 16:26
0

Is your client on same LAN as your server? I think you should re-check IP address / host name and port number to which your client is connecting.

Shekhar
  • 11,438
  • 36
  • 130
  • 186