README.md
Minimal Java 17 TCP server that exchanges JSON messages using a dependency-free JSON implementation.
Designed for student work:
- JSON parser/tree implemented in-house (no Gson/Jackson)
- simple transport + routing you can extend for a real-time game

Contents
Quickstart
1) Build & test
mvn test
2) Run the example server + console client
Terminal A (server):
mvn -DskipTests package
java -cp target/classes com.sae.network.example.ExampleServerMain
Terminal B (client):
java -cp target/classes com.sae.network.example.ExampleConsoleClientMain 127.0.0.1 7777
Then type in the client:
ping
add 5
quit
Default port: 7777.
Features
- Custom JSON tree + parser + writer (
com.sae.network.json.*) - nlohmann::json-inspired access API:
at(...),value(...), typed getters - Blocking TCP server with length-prefixed framing (
com.sae.network.server.tcp.BlockingTcpServer) - Message routing by
type(com.sae.network.server.MessageRouter) - Built-in generic handlers:
ping,echo,health,server_info - Minimal rooms implementation (in-memory)
- Unit tests for JSON + integration test over real sockets
Requirements
- Java 17+
- Maven 3+
Entry points
- Runtime server (configurable):
com.sae.network.app.GameServerMain - Example server (counter + rooms):
com.sae.network.example.ExampleServerMain - Example console client:
com.sae.network.example.ExampleConsoleClientMain
Runtime server with custom parameters:
java -cp target/classes com.sae.network.app.GameServerMain --port 7777 --maxClients 32 --tickHz 60 --netHz 20
Where to start
- Want to build a game server: implement a
com.sae.network.game.GameModuleand runcom.sae.network.app.GameServerMain. - Want to understand the wire format: read the Protocol section and check
com.sae.network.protocol.*. - Want the smallest runnable thing: start
com.sae.network.example.ExampleServerMain+com.sae.network.example.ExampleConsoleClientMain.
Project layout
com.sae.network.json.*: JSON tree + parser/writer (no external libs)com.sae.network.protocol.*: message envelope mapping helperscom.sae.network.game.*: game module + engine interfacescom.sae.network.server.*: routing + handlerscom.sae.network.server.handlers.*: built-in generic handlers + input handlercom.sae.network.server.tcp.*: blocking TCP transport + framingcom.sae.network.server.runtime.*: game loop + bootstrapcom.sae.network.server.rooms.*: minimal rooms managercom.sae.network.example.*: runnable example server/client
Protocol
Transport framing (TCP)
Each message is framed as:
int32(big-endian) lengthlengthbytes of UTF-8 JSON text
JSON envelope
Messages are JSON objects with:
type(string, required)requestId(string|null, optional)payload(any JSON value, optional)
Example request (as JSON text inside the frame):
{ "type": "ping", "requestId": "1", "payload": { "msg": "hello" } }
Example response:
{ "type": "pong", "requestId": "1", "payload": { "serverTime": "...", "echo": { "msg": "hello" } } }
Mapping helpers:
com.sae.network.protocol.MessageEnvelopecom.sae.network.protocol.MessageEnvelopeJson
JSON API quick tour
import com.sae.network.json.Json;
Json root = Json.parse("{\"player\":{\"name\":\"Ada\",\"score\":42}} ");
String name = root.at("player").at("name").getString();
int score = root.at("player").value("score", 0);
String compact = root.stringify();
License
MIT — see LICENCE.