![]() |
VOOZH | about |
This project is a simple Java Socket-based Chat Application that enables multiple clients to connect to a server and exchange messages in real time. It demonstrates core networking concepts such as TCP sockets, multithreading and client-server communication, making it a practical example of how chat systems work.
Before we build this project, we must know Socket in Java. Java Socket connects two different JREs (Java Runtime Environment).
On the Java client side, we will pass the two most important information to the Socket class. This information connects the Java Client Socket to the Java Server Socket.
In the Java client, we create a new thread when each new message is received from the Java Server Client.
In the server side. we will get the username of each connected client and stores each client in the CopyOnWriteArrayList after accepting the connection from the connected client. Every time create another thread for each client. Every message will be broadcast to every connected client.
First Run the Server.js file in the terminal or command Prompt for better visual. Using the following command,
javac Server.java
java Server.java
Now, run the Client.java file in another terminal or command Prompt for better visual. Using the following command,
javac Client.java
java Client.java
Output:
Below is the Output that demonstrates the Basic Socket Communication between a Server and Client.