T
T
Tester172021-01-09 01:25:02
Java
Tester17, 2021-01-09 01:25:02

Why can't a Java client connect to a server (on sockets)?

I wrote a server and client in Java (ServerSocket and Socket). When a client connects via localhost or local ip of a computer on the network (192.168.1.8), everything is fine. When you try to connect via external ip (white, static) or local ip of the router (192.168.1.1) occurs

java.net.ConnectException: Connection refused: connect

Of course, I forwarded the ports, set up a firewall and all that (2ip.ru shows that the port is open), but it still doesn’t want to connect ...
5ff8d987a8b1e361386019.png
5ff8d991f3986058326997.png
5ff8d9996b7d1237854020.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AVSomov, 2021-01-09
@Tester17

With this formulation of the question, it is difficult to give a direct answer, because there is no code or any analysis and dumps.
But it can be clearly noted that working through sockets implies that the programmer takes full responsibility for the correct work with the network. If there is complete confidence in the correctness of the code, then it is worth turning to debugging or administration skills to collect additional diagnostic information.
For example, I can assume that port forwarding through NAT on the WAN interface is not correctly expected when the packet is actually transmitted to the LAN interface of the router. Try to run any sniferr, you will probably see in it a packet to the router to create a connection, but there will be no answer, because It is not clear to the router where to forward this packet. At the same time, a call from an external network via a white IP, with configured forwarding, will show that the exchange is working.

M
mayton2019, 2021-01-11
@mayton2019

There is some kind of general system error here, and the message java.net.ConnectException: Connection refused: connect
does not carry any information at all where to look for the problem. Let's move the task from the Java plane to the network and protocol plane. In general, first you need to pull the port from the outside using the telnet or netcat utilities and then look for errors.
nc -w 3 -zv tester17.com 33333
when you get the message: "Connection .... succeded!" - then you can return to Java coding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question