I am playing with the code https://cs.lmu.edu/~ray/notes/javanetexamples/#chat at the moment. In the line
var client = new ChatClient(args[0]);
of the clients' main method you pass a host name to the constructor.
I am still getting a "ConnectException: connection refused" trying to connect to my server as a client over the internet (with my public IP), whereas I can connect to it locally (with "localhost"). I have checked the firewall, all ports and the server itself, but still getting it. The ping to my IP works, but the connection is being refused.
Is it possible for me to connect as a client over the internet from my laptop to the server running at my laptop?
The trace:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:503)
at java.base/sun.nio.ch.Net.connect(Net.java:492)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
at java.base/java.net.Socket.connect(Socket.java:648)
at java.base/java.net.Socket.connect(Socket.java:597)
at java.base/java.net.Socket.<init>(Socket.java:520)
at java.base/java.net.Socket.<init>(Socket.java:294)
at ChatClient.run(ChatClient.java:71)
at ChatClient.main(ChatClient.java:97)
So, calling client.run()
the exception occurs when trying to open a socket at the passed IP address at
var socket = new Socket(serverAddress, 50000);
and I use the port 50000 for both.