Java network: connection rejected - Yes, my server is running

I get the following error when my client tries to connect to my server socket:

java.net.ConnectException: Connection refused: connect

But my server does work on the same machine. I am trying to connect to it using the external IP address of my router. But when I try to connect with "localhost", it works. And, yes, I correctly passed the port on my router. It canyouseeme.orgcan even connect to my server (the site says “success”, and in my server there is a log that is connected to the server.)

So, for some reason, it is impossible to connect to the same computer (or to a machine on the same network) through an external IP? Or is this something typical of Windows? (I usually use Linux)

I also tried completely disabling the windows firewall.

ServerSocket:

public ServerSocket ssocket;
public List<ClientHandler> handlers;

public Server(int port) { // Constructor
    try {
        ssocket = new ServerSocket(port);
        this.handlers = new ArrayList<ClientHandler>();
        IpSharingManager.uploadData(Utilities.getPublicIp(), port);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

:

public InvisibleClient(String host, int port) {
    try {
        System.out.println("Trying to connect to " + host + ":" + port);
        this.host = host;
        this.socket = new Socket(host, port);
        this.bis = new BufferedInputStream(this.socket.getInputStream());
        this.bos = new BufferedOutputStream(this.socket.getOutputStream());
        this.console = new RemoteConsole(this.socket);
        initializeCommunication();
        System.out.println("Successfully connected!");
        new Thread(this, "Client Thread").start();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("No server available");
    }
}

+2
4

IP- .

telnet . telnet , , , .

+3

java.exe ?

edit: , . , , , . ()

0

JVM: java.net.preferIPv4Stack=true?

0

For what I see in your code, you missed the part where you agree to connect, after creating the server socket instance, you need ssocket.accept () to accept the connections, and then you need to start reading outputstrem from the socket

0
source

All Articles