A multithreaded client-server architecture based Chat Application using Java Socket programming. A server continuously listens for connection requests from clients across the network or even from the same machine. Clients connect to the server using an IP address and port number. The client needs to provide a unique username while connecting to the server. This username is treated as the unique identifier for that client.
All the messages from the client are sent to the server using ObjectOutputStream in java. After receiving the message from the client, the server broadcasts the message if it is not a private message. And if it is a private message, which is detected using ‘@’ followed by a valid username, sends the message only to that user.
All the messages sent from various clients can be seen on the server console.
To compile the Programs
javac ChatServer.java
javac ChatClient.java
Server
To start the server
java ChatServer
java ChatServer [portNumber]
If the port number is not specified, port 5000 is used by default
Starting the Chat Server
Client
To start the Client in console mode use one of the following command
java ChatClient username
java ChatClient username portNumber
java ChatClient username portNumber serverAddress
At the console prompt
- If the portNumber is not specified 5000 is used
- If the serverAddress is not specified "localHost" is used
Starting the Chat Client
Chat
On the client console:
- Simply type the message to send broadcast to all the active users
- Type '@usernameyourmessage' without quotes to send message to desired client
- Type 'GETUSERS' without quotes to see list of active clients
- Type 'SIGNOUT' without quotes to logoff from server
In the screenshots below, three clents namely "Aditya", "Abhishek" and "Himanshu" are active on the chat server.
Console of the Chat Server
Console of user Aditya
Console of user Abhishek
Console of user Himanshu
This project is licensed under the MIT License - see the LICENSE file for details