xMessageClient is a pure Java WebSocket client application built with Maven. It is designed to interact with a messaging server using a custom protocol. The client supports secure communication via AES encryption, automatic reconnection, heartbeat mechanisms (Ping/Pong), and various messaging events such as private messages and group management.
- Pure Java: Built with standard Java and Maven, no Spring Boot dependency.
- WebSocket Client: Uses
OkHttp3for robust WebSocket connections. - Resilience: Implements automatic disconnection detection and reconnection strategies.
- Security: Messages (except login) are encrypted using AES (via
Hutool), ensuring data privacy. - Heartbeat: Sends Ping messages every 5 seconds to maintain connection health.
- JSON Handling: Uses
FastJsonfor efficient JSON serialization and validation. - Interactive CLI: Provides a command-line interface to test various messaging functions.
- Java 8+
- Maven: Build and dependency management.
- OkHttp3: WebSocket client implementation.
- FastJson: JSON processing.
- Hutool: AES encryption utilities.
- SLF4J: Logging facade.
- Java Development Kit (JDK) 8 or higher
- Maven
- Clone the repository.
- Navigate to the project directory.
You can compile and run the client using Maven commands:
# Clean and compile
mvn clean compile
# Run the application
mvn exec:javaOnce the application is running and connected to the server (default: ws://127.0.0.1:9922), you can use the following commands in the console:
pm: Send a private message to user3000_2102.cg: Create a new group (with users 3000_2101, 3000_2102, 3000_2103).jg: Join a group (user 3000_2104).lg: Leave a group (user 3000_2102).gm: Send a message to the group.dg: Dismiss (delete) the group.setgid <id>: Manually set the target Group ID for testing.exit: Close the client.
The client handles the following event IDs:
1000000: Login (Plaintext)1000001: Receive Private Message (Auto-replies with ACK1000002)1000002: ACK (Acknowledgement)5000001: Create Group5000002: Join Group5000003: Dismiss Group5000004: Send Group Message5000005: Leave Group9000000: Ping (Heartbeat)
xMessageClient 是一个基于 Maven 构建的纯 Java WebSocket 客户端应用。它专为与自定义消息服务器交互而设计。该客户端支持 AES 加密通信、断线自动重连、心跳机制(Ping/Pong)以及私聊、群组管理等多种消息事件。
- 纯 Java 构建: 不依赖 Spring Boot,轻量级 Maven 工程。
- WebSocket 客户端: 使用
OkHttp3实现稳定的 WebSocket 连接。 - 高可用性: 支持断线检测与自动重连机制。
- 安全通信: 除登录消息外,所有业务数据均通过 AES 加密传输(使用
Hutool工具包)。 - 心跳机制: 每 5 秒发送一次 Ping 消息以维持连接活跃。
- JSON 处理: 集成
FastJson进行高效的 JSON 序列化与验证。 - 交互式命令行: 提供控制台命令以测试各种消息功能。
- Java 8+
- Maven: 项目构建与依赖管理。
- OkHttp3: WebSocket 客户端核心库。
- FastJson: JSON 数据处理。
- Hutool: AES 加密工具。
- SLF4J: 日志门面。
- Java Development Kit (JDK) 8 或更高版本
- Maven
- 克隆代码仓库。
- 进入项目根目录。
使用 Maven 命令即可编译并启动客户端:
# 清理并编译
mvn clean compile
# 运行应用程序
mvn exec:java程序启动并连接到服务器(默认:ws://127.0.0.1:9922)后,您可以在控制台输入以下指令进行操作:
pm: 发送私聊消息给用户3000_2102。cg: 创建群组(包含用户 3000_2101, 3000_2102, 3000_2103)。jg: 加入群组(用户 3000_2104)。lg: 离开群组(用户 3000_2102)。gm: 发送群组消息。dg: 解散群组。setgid <id>: 手动设置测试用的群组 ID。exit: 退出客户端。
客户端支持处理以下事件 ID:
1000000: 登录(明文传输)1000001: 接收私聊消息(自动回复 ACK1000002)1000002: ACK(消息确认)5000001: 创建群组5000002: 加入群组5000003: 解散群组5000004: 发送群组消息5000005: 离开群组9000000: Ping(心跳包)