[FREE] Chat Client and Server

I formatted it like this:

  • SendMessage: Sends all information to the server, but the server only returns the message to the client.
  • SendMessageWithDetails: Sends all information to the server, but the server only returns the message and items to the client.

Note: We still need to add a key exchange service.

but no "items" (IP/timestamp/UID) are shown by the MessageReceived event, only the message sent....

Understood

Thanks! I will add!

until it works as promoted

Eventually got it to work as expected, after modifying the extension and the ChatServer.

Main Changes

  • Delimiter is changed from , to ;;, which should allow for commas in message text
  • SendMessage now sends: message, timestamp, ip, and uid
  • ChatMessageReceived provides the above four items on message return (to allow for decrypting of encrypted message) and options for the developer
  • SendMessageWithDetails is therefore no longer required
  • Revised extension built with RUSH
JAVA

ChatServer.java.txt (5.9 KB)
ChatClient.java.txt (9.0 KB)

EXTENSION

io.chatclientV3.aix (15.7 KB)

BLOCKS

AIA

ChatServerExtnTestV3.aia (19.5 KB)

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 :wink: :dog2:

1 Like

Good! The extension already sends messages online, just run ChatServe.java on a remote server.

Well it is not working for me:

on remote server:

~$ 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)

Tomorrow I will connect my server for you to test

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));

My test on remote server:

image

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?

You would need to pass on your server's public IP over to the InetSocketAddress()

I will try it see what gives....

1 Like

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....

Are you trying to pass it as an argument from command line? Try to explicitly declare it in the code.

Would you like to help implement the key exchange mechanism? Honestly, I don't have the properties for that.

1 Like

In ChatServer.java

    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

OK, got it to compile, by importing java.net.*

However, still no connection with nping/nmap....

Possibility, I could help you, also maybe I could contribute something to the project :grinning_face_with_smiling_eyes: