Skip to content

xMessageClient is a pure Java WebSocket client application built with Maven

Notifications You must be signed in to change notification settings

teammors/xteammors-message-client-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

xMessageClient

English | 中文


English

Introduction

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.

Features

  • Pure Java: Built with standard Java and Maven, no Spring Boot dependency.
  • WebSocket Client: Uses OkHttp3 for 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 FastJson for efficient JSON serialization and validation.
  • Interactive CLI: Provides a command-line interface to test various messaging functions.

Tech Stack

  • Java 8+
  • Maven: Build and dependency management.
  • OkHttp3: WebSocket client implementation.
  • FastJson: JSON processing.
  • Hutool: AES encryption utilities.
  • SLF4J: Logging facade.

Getting Started

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Maven

Installation

  1. Clone the repository.
  2. Navigate to the project directory.

Build & Run

You can compile and run the client using Maven commands:

# Clean and compile
mvn clean compile

# Run the application
mvn exec:java

Usage

Once 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 user 3000_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.

Protocol Events

The client handles the following event IDs:

  • 1000000: Login (Plaintext)
  • 1000001: Receive Private Message (Auto-replies with ACK 1000002)
  • 1000002: ACK (Acknowledgement)
  • 5000001: Create Group
  • 5000002: Join Group
  • 5000003: Dismiss Group
  • 5000004: Send Group Message
  • 5000005: Leave Group
  • 9000000: Ping (Heartbeat)

Chinese (中文)

简介

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

安装步骤

  1. 克隆代码仓库。
  2. 进入项目根目录。

构建与运行

使用 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: 接收私聊消息(自动回复 ACK 1000002
  • 1000002: ACK(消息确认)
  • 5000001: 创建群组
  • 5000002: 加入群组
  • 5000003: 解散群组
  • 5000004: 发送群组消息
  • 5000005: 离开群组
  • 9000000: Ping(心跳包)

About

xMessageClient is a pure Java WebSocket client application built with Maven

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages