Skip to content

eiabhiram/java-coffee-socket-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

β˜• Java Coffee Socket Demo

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.

πŸš€ Features

βœ” Java BIO Version

  • Uses ServerSocket + Socket
  • Blocking read/write
  • One thread per client (classic approach)

βœ” Java NIO Version

  • Uses Selector, ServerSocketChannel, SocketChannel
  • Non-blocking I/O
  • Event-driven architecture
  • Single-threaded high scalability

βœ” Netty Version

  • Uses industry-standard networking framework
  • EventLoopGroups + pipelines
  • Automatic encoding/decoding
  • Clean, simple handlers
  • High-performance, production-grade networking

πŸ“‚ Project Structure

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

▢️ Running the Project

1. BIO Version

Start the server:

java javaio.CoffeeShopServer

Start the client:

java javaio.CoffeeCustomer

2. NIO Version

Start the server:

java javanio.NioCoffeeServer

Start the client:

java javanio.NioCoffeeCustomer

3. Netty Version (recommended)

Start the server:

java netty.NettyCoffeeServer

Start the client:

java netty.NettyCoffeeCustomer

πŸ“¦ Dependencies

If using plain Java project, place this JAR into /lib and add to Build Path:

netty-all-4.1.109.Final.jar

πŸ“˜ Learning Goals

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.

⭐ License

Free to use and modify.

About

Simple TCP application using Java IO, New IO and Netty

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages