Nobody01100001
Nobody01100001

Reputation: 28

JavaSocket connection timed out

I am creating a encrypted communications terminal using Java Sockets. My problem is that when I connect over "localhost" or my computers LAN address, the program connects perfectly and works as expected, but when I connect using my public IP address, the connection is refused and I get

java.net.ConnectException: Connection timed out: connect at java.base/java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.base/java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.base/java.net.PlainSocketImpl.connect(Unknown Source) at java.base/java.net.SocksSocketImpl.connect(Unknown Source) at java.base/java.net.Socket.connect(Unknown Source) at java.base/java.net.Socket.connect(Unknown Source) at java.base/java.net.Socket.(Unknown Source) at java.base/java.net.Socket.(Unknown Source) at net.wolvenservices.clientcomms.Launcher.main(Launcher.java:27)

here is the main method for my server:

try{
   serv = new ServerSocket(200);
   sock = serv.accpet();
   System.out.println(sock.getInetAddress() + ": user has connected");
   in = new DataInputStream(sock.getInputStream());
   out = new DataOutputStream(sock.getOutputStream());
}catch(IOException e){e.printStackTrace();}

main method for client

try{
   sock = new Socet("[MyPublicIP]", 200);  //this is line 27
   in = new DataInputStream(sock.getInputStream());
   out = new DataOutputStream(sock.getOutputStream());
   ...
catch(IOException e) {e.printStackTrace();}

The reason that I wont give MyPublicIP is for obvious safety reasons.

Edit: yes, I have tested pinging the machine, I have tested telnet, and I have used disabled windows firewall and port forwarded, even enabling DMZ for this specific machine.

Upvotes: 0

Views: 1070

Answers (1)

dehasi
dehasi

Reputation: 2773

You can try to set a timeout on your own.

There is a public synchronized void setSoTimeout(int timeout) method.

A timeout of zero is interpreted as an infinite timeout.

Upvotes: 0

Related Questions