A dependency-free networking project that demonstrates reliable, bidirectional communication between a concurrent Python TCP server and a Java client. The two programs exchange validated messages through a custom, versioned application-layer protocol called CSNP/1.0.
| Python Concurrent Server | Java Interactive Client (REPL) |
|---|---|
![]() |
![]() |
- Cross-language communication over persistent TCP connections
- Concurrent client handling with one lightweight server thread per connection
- Versioned request/response protocol with unique request IDs
- UTF-8 payloads encoded with Base64 to safely preserve delimiters and Unicode
- Strict frame-size, field, command, version, and payload validation
- Graceful handling of malformed frames, timeouts, disconnects, and connection failures
- Unit, integration, and Java-to-Python end-to-end tests
- GitHub Actions continuous integration on every push and pull request
flowchart LR
A[Java CLI Client] -->|CSNP/1.0 requests over TCP| B[Python Threaded Server]
B --> C[Protocol Validator]
C --> D[Command Handler]
D -->|Correlated responses| A
Each client keeps a persistent socket open and can issue multiple commands. The server creates an isolated handler thread for each connection, validates every frame before dispatch, and returns a response carrying the same request ID.
CSNP/1.0 uses one newline-delimited UTF-8 frame per message. Each frame is limited to 4,096 bytes.
Request
CSNP/1.0|<request-id>|<command>|<base64-payload>
Response
CSNP/1.0|<request-id>|<OK-or-ERROR>|<base64-payload>
Example request and response for ECHO Hello:
CSNP/1.0|demo-1|ECHO|SGVsbG8=
CSNP/1.0|demo-1|OK|SGVsbG8=
| Command | Payload | Response |
|---|---|---|
PING |
Optional | PONG |
ECHO |
Any UTF-8 text | Original payload |
TIME |
Optional | Current UTC timestamp |
STATS |
Optional | Thread-safe server metrics |
QUIT |
Optional | Acknowledgement, then graceful disconnect |
- Python 3.10+
- Java 17+ (JDK)
git clone [https://github.com/aayushkeshari/client-server-networking-system.git](https://github.com/aayushkeshari/client-server-networking-system.git)
cd client-server-networking-systemEnsure your terminal is inside the repository root, then launch the server:
python3 -m server.serverThe server will start listening on 127.0.0.1:5050 by default.
Open a new terminal window or tab (Cmd + T), navigate to the project directory, and connect:
cd ~/client-server-networking-systemmake clientOnce connected, enter protocol commands directly into the csnp> prompt:
Connected to 127.0.0.1:5050 using CSNP/1.0
Commands: PING, ECHO <message>, TIME, STATS, QUIT
csnp> PING
[OK] PONG
csnp> ECHO Hello from Java
[OK] Hello from Java
csnp> STATS
[OK] active_connections=1, total_connections=1, requests_processed=2, protocol_errors=0
csnp> QUIT
[OK] Connection closing
# Compile client classes
mkdir -p build/classes
javac -d build/classes $(find client/src -name '*.java')
# Send a single PING command
java -cp build/classes com.aayush.networking.Main --host 127.0.0.1 --port 5050 --command ping
# Send a single ECHO command
java -cp build/classes com.aayush.networking.Main --host 127.0.0.1 --port 5050 --command echo --message "Hello from Java"Run the Python unit and server integration test suites:
make testExecute the automated cross-language end-to-end integration test:
make e2e.
├── client/src/com/aayush/networking/
│ ├── Main.java # Interactive REPL & CLI interface
│ ├── Protocol.java # Message framing, parsing & validation
│ ├── ProtocolException.java # Protocol error declarations
│ └── TcpClient.java # Socket lifecycle & correlation engine
├── server/
│ ├── protocol.py # Protocol parser, serializer & validator
│ └── server.py # Threaded socket server & command handlers
├── tests/
│ ├── test_protocol.py # Codec unit tests
│ └── test_server.py # Integration & concurrency tests
├── scripts/e2e_test.sh # Automated cross-language test runner
├── .github/workflows/ci.yml # Continuous integration pipeline
└── Makefile # Build, test, and run automation
- TCP over UDP: Ordered, reliable delivery fits request/response messaging and lets the project focus on application-layer behavior.
- A small custom protocol: Makes framing, validation, encoding, versioning, and cross-language interoperability explicit instead of hiding them behind a framework.
- Newline-delimited frames: Simple to inspect and stream while still supporting persistent connections.
- Base64 payloads: Prevents embedded delimiters and newlines from corrupting a frame while preserving arbitrary UTF-8 text.
- Thread-per-connection server: Keeps connection state isolated and makes simultaneous client sessions easy to understand. For very high concurrency, an async event loop would reduce per-connection overhead.
- TLS transport and client authentication
- Length-prefixed binary framing for larger payloads
- Heartbeats, retry policies, and idempotency keys
- Async I/O for high-concurrency workloads
- Persistent metrics and structured JSON logging
This project is available under the MIT License.

