Now what is needed is the ability to run the ChatServer on a remote server (online), otherwise all I can do with it is send messages to myself and my dog
~$ sudo ufw status
Status: active
To Action From
-- ------ ----
12345/tcp ALLOW Anywhere
12345 ALLOW Anywhere
12345/tcp (v6) ALLOW Anywhere (v6)
12345 (v6) ALLOW Anywhere (v6)
~$ java ChatServer
[1] 42130
~$ Server listening on port 12345
when ChatServer running:
~$ ss -lntu
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 511 *:80 *:*
tcp LISTEN 0 50 *:12345 *:*
tcp LISTEN 0 511 *:443 *:*
on local computer:
~$ nmap -p 12345 xx.xx.114.189
Starting Nmap 7.80 ( https://nmap.org ) at 2023-11-09 12:57 GMT
Nmap scan report for xx.xx.114.189
Host is up (0.014s latency).
PORT STATE SERVICE
12345/tcp filtered netbus
Nmap done: 1 IP address (1 host up) scanned in 0.25 seconds
~$ nping -p 12345 xx.xx.114.189
Starting Nping 0.7.80 ( https://nmap.org/nping ) at 2023-11-09 12:57 GMT
SENT (0.0013s) Starting TCP Handshake > xx.xx.114.189:12345
SENT (1.0035s) Starting TCP Handshake > xx.xx.114.189:12345
SENT (2.0045s) Starting TCP Handshake > xx.xx.114.189:12345
SENT (3.0057s) Starting TCP Handshake > xx.xx.114.189:12345
SENT (4.0069s) Starting TCP Handshake > xx.xx.114.189:12345
Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A
TCP connection attempts: 5 | Successful connections: 0 | Failed: 5 (100.00%)
Nping done: 1 IP address pinged in 5.01 seconds
I get the same response even if I disable the firewall (ufw)
The ChatServer and port respond successfully if tested locally (on the remote server)
When you are running on a remote server, try to explicitly mention the Hostname (of the remote server) when you create the ServerSocket object. Check the ServerSocket.bind(inetAddress) method.
ServerSocket server = new ServerSocket();
server.bind(new InetSocketAddress(hostname, port));
Yes, I saw that as an option. My server only has an external IP, I serve 6/7 websites from the using Apache. So what IP do I use, the external or the internal/ localhost?
Hmmm, javac doesn't like an IP address (xy.xy.xyx.xyx) either as it is or in quotes. I saw somewhere it needs to be broken down into parts, will seek that out again....
private static final int PORT = 12345;
private static final String hostname = "xy.xy.xyz.xyz";
private static final String KEY = "MySuperSecretKey"; // 16-byte key
private static final String ALGORITHM = "AES";
// Create a thread-safe list to hold all client handlers
private static final List<ClientHandler> clients = new CopyOnWriteArrayList<>();
public static void main(String[] args) throws Exception {
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress(hostname, PORT));
System.out.println("Server listening on port " + PORT);
From javac:
ChatServer.java:56: error: cannot find symbol
serverSocket.bind(new InetSocketAddress(hostname, PORT));
^
symbol: class InetSocketAddress
location: class ChatServer
1 error