WuKongIM Protocol
WuKongIM protocol is an efficient binary communication protocol designed specifically for instant messaging scenarios. This document provides detailed descriptions of packet structure, control types, and encoding specifications.
📋 Control Packet Structure
Each WuKongIM control packet consists of the following three parts:🔧 Fixed Header
Each WuKongIM control packet contains a fixed header used to identify packet type and length information.📝 WuKongIM Control Packet Types
WuKongIM protocol defines 10 different control packet types, each with specific purposes and data structures.
🏷️ Control Packet Flag Bits
Different protocol packets use different flag bits to control message behavior: Flag bits in Send and Recv protocols
Flag bits in Connack protocol
Flag bits in Chunk protocol
📏 Remaining Length Encoding
Encoding rules:- Single byte maximum value:
01111111(0x7F, 127) - The eighth bit (most significant bit) being 1 indicates there are subsequent bytes
- Maximum of 4 bytes allowed to represent remaining length
- Maximum length:
0xFF,0xFF,0xFF,0x7F= 268,435,455 bytes = 256MB
Encoding understanding:
- 1st byte base: 1
- 2nd byte base: 128 (2^7)
- 3rd byte base: 128×128 = 2^14
- 4th byte base: 128×128×128 = 2^21
11000001 00000010
🔤 String UTF-8 Encoding
WuKongIM uses a modified UTF-8 encoding format:🔄 Variable Header
Some control packets contain a variable header section located between the fixed header and payload. The content of the variable header varies depending on the packet type.
📡 Protocol Packet Specifications
🔌 CONNECT Connection Packet
Packet format used when a client initiates a connection request to the server.
✅ CONNACK Connection Acknowledgment
📤 SEND Send Message
Packet format used when a client sends a message to the server.
✅ SENDACK Send Message Acknowledgment
Server acknowledgment response to client message sending.
📥 RECV Receive Message
Packet format used when the server pushes messages to the client.
✅ RECVACK Receive Message Acknowledgment
Client acknowledgment response to server message push.
🏓 PING
Heartbeat request packet sent by the client to keep the connection active.
🏓 PONG
Server response packet to client PING request.
🔌 DISCONNECT
⚙️ Message Settings
📊 Message Setting Bit Fields
Message settings are 1 byte (8 bits) used to control various message behavior characteristics.
🔧 Setting Bit Descriptions
Complete Protocol Documentation: This document contains the core parts of the WuKongIM protocol. The complete protocol specification also includes recommended Payload structure, regular message format, system message format, and other detailed content. Please refer to the source documentation for complete information.

