[update]
As you would expect, a connection timeout indicates some network problem. Packets from your client do not arrive on the server machine. The exact solution will depend on the type of router, but the term google for is "port forwarding." Here is an article I randomly found to help: http://www.rhinosoft.com/KnowledgeBase/kbarticle.asp?RefNo=1289
Basically, you program the router so that any connection request on port 31350 is redirected to your computer on the LAN at the local IP address.
Good luck
[original comment]
This is more of a comment than an answer (but I need an extra room). The logic of your logic is trying to significantly complicate the diagnosis of the problem. Simplify the code as follows:
public static void main(String[] args) throws IOException, UnknownHostException { Socket socket;
Just let the original IOException propagate and update your question to enable traceability of the exception stack. The original exception contains valuable information - if it says that the connection was refused, it means one thing: your port number may be incorrect. If he says that the connection timeout means something else - either you really have a problem with the firewall, or maybe your IP address is incorrect.
Your code catches a useful exception, swallows it, and throws a much less useful exception.
Do the same with the server code:
public static void main (String[] args) throws IOException { ServerSocket server = new ServerSocket(31350); Socket client1 = client1 = server.accept(); }
The stack trace will show which method threw the exception, so you don’t need redundant text like InetAddress creation failed
source share