//LAST UPDATE
cd "/Users/harshanaamuwatte/Projects/Academic/Enhanced chat" export CHAT_ADMIN_TOKEN="admin123" ./run-server.sh 7200
cd "/Users/harshanaamuwatte/Projects/Academic/Enhanced chat" ./run-ws-bridge.sh --chat-port 7200 --ws-port 8081
cd "/Users/harshanaamuwatte/Projects/Academic/Enhanced chat/web" python3 -m http.server 8000
./run-server.sh 7210
./run-ws-bridge.sh --ws-port 8081 --chat-host 127.0.0.1 --chat-port 7210
python3 -m http.server 5500 -d web
A lightweight multi-threaded TCP chat server implemented in pure Java (no external libraries). Each connecting client is handled by a dedicated thread (ClientHandler). Messages from one client are broadcast to all other connected clients.
Run backend (server):
./run-server.sh 7210Run web frontend:
./run-ws-bridge.sh --ws-port 8081 --chat-host 127.0.0.1 --chat-port 7210
python3 -m http.server 5500 -d webOpen http://localhost:5500 and set WS URL to ws://localhost:8081. Use the file picker to upload files to Everyone or a selected user.
- Concurrent client handling using threads
- Line-based text messaging
- Join/leave notifications
- Graceful client disconnect with
/quit - Private messaging with
/private <user> <message> - File transfer with
/sendfile (<user>) <path>
src/chatserver/Server.java
src/chatserver/ClientHandler.java
src/chatserver/FileReceiver.java
FileSender.java
ChatServer.java
ChatClient.java
From project root (produces classes runnable directly):
javac -d . src/chatserver/*.java ChatServer.java ChatClient.javaStart server on default port 5000 (after compiling with -d .):
java ChatServerSpecify port:
java ChatServer 6000Or use the helper script (builds then runs):
./run-server.sh # uses 5000
./run-server.sh 7205 # choose custom portThe server also opens a file listener on port+1.
Run a client (host, port optional):
java ChatClientConnect to custom host/port:
java ChatClient 127.0.0.1 6000Launch the Swing GUI (LoginUI → Chat window):
java GuiChatClient
# or
./run-gui.shIn the login dialog, set host to your server (e.g., 127.0.0.1) and the chat port (e.g., 7205).
Important: connect clients to the chat port (e.g., 7205). The file transfer listener uses port+1 (e.g., 7206) and is not for chat connections.
The browser can’t open raw TCP sockets, so use the WebSocket bridge to connect the web UI to the Java chat server.
- Start the chat server (example
7210):
./run-server.sh 7210- In a new terminal, start the WebSocket bridge (example bridge on
8081):
./run-ws-bridge.sh --ws-port 8081 --chat-host 127.0.0.1 --chat-port 7210- Open
web/index.htmlin your browser (no server required). Set WS URL to:
ws://localhost:8081
Click Connect, then chat. Use the Private form or /private <user> <msg>.
Notes:
- The bridge is a minimal RFC6455 implementation (text frames only).
- File transfer from the browser is not implemented; use console client for
/sendfile.
From inside a running client session:
/sendfile sample.txt
Sends sample.txt to all users (broadcast receipt notice).
Target a specific user:
/sendfile User2 sample.txt
Files are uploaded to the server uploads/ directory. Only the target user receives a receipt message (or all if *).
nc 127.0.0.1 5000
# or
telnet 127.0.0.1 5000Type messages and press Enter to send. Use /quit to disconnect.
- Server sends a welcome line on connect.
- Plain text lines are broadcast prefixed with the user's auto-assigned name (
UserN). /quittriggers a clean disconnect./private <user> <message>sends a direct message only to the target user./sendfile (<user>) <path>opens a secondary connection onport+1and sends header:FILE <filename> <size> <target>followed by raw bytes.<target>is*for broadcast notice or a specific username.- Server saves file under
uploads/<filename>; no automatic download channel yet.
- Add username negotiation.
- Implement private messaging (e.g.,
/msg User2 hi). - Add server-side command to list users.
- Persist chat history.
(No license specified; internal academic use.)