This is a simple Java-based socket programming project that demonstrates a TCP-based client-server system. The server receives input from the client, reverses the message, waits for a few seconds (to simulate processing), and then sends the reversed message back to the client.
Socket programming is a way to enable communication between two machines over a network. In Java, this involves:
- 🧱 A ServerSocket that listens on a specific port
- 🔌 A Socket on the client side to connect to the server
- 📬 Input/Output streams to send and receive data
This project uses TCP sockets, which means the communication is connection-oriented, reliable, and data is received in order.
The following diagram shows how the client and server interact:
- Server starts and listens on a port (
2000) - Client connects to the server
- Client sends a message
- Server reverses the message and returns it
- Communication ends when the message
"end"is sent
Here’s a snapshot of the actual working:
- Client sends
hello - Server returns
olleh - Communication continues until
end(which becomesdnereversed)
| Concept | Description |
|---|---|
ServerSocket |
Accepts incoming TCP connections |
Socket |
Used by both client and server to exchange data |
BufferedReader / PrintStream |
For input and output stream handling |
Thread.sleep() |
Simulates server delay |
try-with-resources |
Ensures clean closing of sockets and streams |
javac ReverseEcho.java
javac Client.java

