A fun and educational Java networking project demonstrating:
- Java Blocking I/O (BIO) sockets
- Java Non-Blocking I/O (NIO) with selectors
- A high-performance Netty server and client
The project simulates a small “coffee shop” where a client sends a coffee order, and the server replies with the prepared drink.
It’s designed as a progression from BIO → NIO → Netty so beginners can understand how networking evolves from simple to high-performance frameworks.
- Uses
ServerSocket+Socket - Blocking read/write
- One thread per client (classic approach)
- Uses
Selector,ServerSocketChannel,SocketChannel - Non-blocking I/O
- Event-driven architecture
- Single-threaded high scalability
- Uses industry-standard networking framework
- EventLoopGroups + pipelines
- Automatic encoding/decoding
- Clean, simple handlers
- High-performance, production-grade networking
java-coffee-socket-demo/
│
├─ javaio/ → Blocking I/O version
│ ├─ CoffeeShopServer.java
│ └─ CoffeeCustomer.java
│
├─ javanio/ → Non-blocking NIO version
│ ├─ NioCoffeeServer.java
│ └─ NioCoffeeCustomer.java
│
├─ netty/ → Netty version (recommended)
│ ├─ NettyCoffeeServer.java
│ └─ NettyCoffeeCustomer.java
│
├─ lib/ → Netty JAR (if plain Java project)
│
└─ README.md
Start the server:
java javaio.CoffeeShopServer
Start the client:
java javaio.CoffeeCustomer
Start the server:
java javanio.NioCoffeeServer
Start the client:
java javanio.NioCoffeeCustomer
Start the server:
java netty.NettyCoffeeServer
Start the client:
java netty.NettyCoffeeCustomer
If using plain Java project, place this JAR into /lib and add to Build Path:
netty-all-4.1.109.Final.jar
This project helps you understand:
- How sockets work in Java
- Blocking vs non-blocking I/O
- Selectors and events
- How Netty simplifies networking
- How real servers handle connections
Perfect for beginners learning networking step-by-step.
Free to use and modify.