JSON-RPC Protocol
Overview
WuKongIM uses the JSON-RPC 2.0 specification for communication. All requests, responses and notifications follow the JSON-RPC 2.0 standard structure.Protocol Field Description
jsonrpc: Optional string, fixed as “2.0”. If omitted, server should assume it’s “2.0”method: Method name for request or notificationparams: Parameters for request or notification, usually an objectid: Unique identifier for request (string type). Response must contain the same id as request. Notifications don’t have idresult: Result data for successful responseerror: Error object for error response
Complete protocol schema can be found at: wukongim_rpc_schema.json
Important Notes
Common Components
ErrorObject
When request processing fails, this object will be included in the response:Header
Optional message header information:SettingFlags
Message setting flags:Core Message Types
1. Connection Authentication (Connect)
Connect Request
The first request initiated by client, used to establish connection and authentication. Parameters (params)
Example Request
Connect Response
Success Response (result)
Example Success Response
2. Send Message
Send Request
Send message to specified channel. Parameters (params)
Example Request
Send Response
Success Response (result)
Example Success Response
3. Receive Message (Notification)
Server pushes messages to client. Parameters (params)
Example Notification
4. Ping/Pong
Ping Request
Client sends ping to keep connection alive. Example RequestPong Response
Example Response5. Disconnect
Disconnect Request
Client initiates disconnection. Parameters (params)
Example Request
Error Codes
Common error codes and their meanings:Best Practices
-
Connection Management
- Always authenticate within 2 seconds after connection
- Send ping regularly to maintain connection
- Handle reconnection gracefully
-
Message Handling
- Use unique
clientMsgNofor each message - Handle message deduplication on client side
- Implement proper error handling
- Use unique
-
Performance Optimization
- Batch multiple operations when possible
- Use appropriate channel types
- Implement message queuing for offline scenarios

