mirror of
https://github.com/tiennm99/try-solver.git
synced 2026-06-09 08:13:23 +00:00
5ad793e06908382ede889e90d9ae56116aeed6c4
Netty WebSocket Game Server
A simple game server implementation using Netty 4 with WebSocket support.
Features
- WebSocket-based game server using Netty 4
- JSON message protocol for client-server communication
- Built-in HTTP server for serving the web client
- Simple web-based test client
Prerequisites
- Java 11 or higher
- Maven 3.6 or higher
Building the Project
mvn clean package
Running the Server
java -cp target/netty-game-server-1.0-SNAPSHOT.jar com.gameserver.GameServer
By default, the server runs on port 8080. You can specify a different port as a command-line argument:
java -cp target/netty-game-server-1.0-SNAPSHOT.jar com.gameserver.GameServer 9000
Testing the Server
- Start the server using the instructions above
- Open a web browser and navigate to
http://localhost:8080 - Use the web interface to send test messages to the server
Message Protocol
The server uses a simple JSON-based message protocol:
{
"type": "MESSAGE_TYPE",
"payload": "Message content"
}
Supported Message Types
PING: Basic ping message- Any other type will be echoed back with a
SERVER_RESPONSEtype
Project Structure
GameServer.java: Main server class that initializes NettyGameWebSocketHandler.java: Handles WebSocket frame processingGameMessage.java: Message model for client-server communicationHttpStaticFileHandler.java: Serves static web contentindex.html: Web-based test client
Description
Languages
Java
81.3%
HTML
18.7%