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.