Skip to main content

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 notification
  • params: Parameters for request or notification, usually an object
  • id: Unique identifier for request (string type). Response must contain the same id as request. Notifications don’t have id
  • result: Result data for successful response
  • error: Error object for error response
Complete protocol schema can be found at: wukongim_rpc_schema.json

Important Notes

  1. After establishing WebSocket connection, authentication (connect) must be performed within 2 seconds. Connections exceeding 2 seconds or failing authentication will be disconnected
  2. Send ping packets regularly to let server know you’re alive (recommended interval around 1-2 minutes)

Common Components

ErrorObject

When request processing fails, this object will be included in the response: 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
Error 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 Request

Pong Response

Example Response

5. Disconnect

Disconnect Request

Client initiates disconnection. Parameters (params) Example Request

Error Codes

Common error codes and their meanings:

Best Practices

  1. Connection Management
    • Always authenticate within 2 seconds after connection
    • Send ping regularly to maintain connection
    • Handle reconnection gracefully
  2. Message Handling
    • Use unique clientMsgNo for each message
    • Handle message deduplication on client side
    • Implement proper error handling
  3. Performance Optimization
    • Batch multiple operations when possible
    • Use appropriate channel types
    • Implement message queuing for offline scenarios