tencent cloud

Tencent Real-Time Communication

Release Notes and Announcements
Release Notes
Recent Product Announcement
TRTC Live (TUILiveKit) Product Launch Announcement
TRTC Conference Official Editions Launched
The commercial version of Conference is coming soon
Terms and Conditions Applicable to $9.9 Starter Package
Rules for the "First Subscription $100 Discount" Promotion
Announcement on the Start of Beta Testing for Multi-person Audio and Video Conference
TRTC Call Official Editions Launched
License Required for Video Playback in New Version of LiteAV SDK
TRTC to Offer Monthly Packages
Product Introduction
Overview
Concepts
Features
Strengths
Use Cases
Performance Statistics
Tencent RTC Quickplay: Experience Ultimate Real-Time Audio and Video Interaction!
Purchase Guide
Billing Overview
Free Minutes
Monthly subscription
Pay-as-you-go
TRTC Overdue and Suspension Policy
FAQs
Refund Instructions
User Tutorial
Free Demo
Call
Overview
Activate the Service
Run Demo
Integration
Offline Call Push
Conversational Chat
On-Cloud Recording
AI Noise Reduction
UI Customization
Calls integration to Chat
Additional Features
No UI Integration
Server APIs
Client APIs
Solution
ErrorCode
Release Notes
FAQs
Conference
Overview(TUIRoomKit)
Activate the Service (TUIRoomKit)
Run Demo(TUIRoomKit)
Integration(TUIRoomKit)
Screen Sharing (TUIRoomKit)
Schedule a meeting (TUIRoomKit)
In-meeting Call (TUIRoomKit)
UI Customization(TUIRoomKit)
Virtual Background (TUIRoomKit)
Conference Control (TUIRoomKit)
Cloud Recording (TUIRoomKit)
AI Noise Reduction (TUIRoomKit)
In-Conference Chat (TUIRoomKit)
Robot Streaming (TUIRoomKit)
Enhanced Features (TUIRoomKit)
Client APIs (TUIRoomKit)
Server APIs (TUIRoomKit)
FAQs (TUIRoomKit)
Error Code (TUIRoomKit)
SDK Update Log (TUIRoomKit)
Live
Billing of Video Live Component
Overview
Activating the Service (TUILiveKit)
Run Demo
No UI Integration
UI Customization
Live Broadcast Monitoring
Video Live Streaming
Voice Chat Room
Advanced Features
Client APIs
Server APIs
Error Codes
Release Notes
FAQs
RTC Engine
Activate Service
SDK Download
API Examples
Usage Guidelines
API Reference Manual
Advanced Features
AI Integration
Overview
Configure MCP Server
Install Skills
Integration Guide
FAQ
RTC RESTFUL API
History
Introduction
API Category
Room Management APIs
Stream mixing and relay APIs
On-cloud recording APIs
Data Monitoring APIs
Pull stream Relay Related interface
Web Record APIs
AI Service APIs
Cloud Slicing APIs
Cloud Moderation APIs
Making API Requests
Call Quality Monitoring APIs
Usage Statistics APIs
Data Types
Appendix
Error Codes
Console Guide
Application Management
Package Management
Usage Statistics
Monitoring Dashboard
Development Assistance
Solution
Real-Time Chorus
FAQs
Migration Guide
Billing
Features
UserSig
Firewall Restrictions
How to Downsize Installation Package
Android and iOS
Web
Flutter
Electron
TRTCCalling for Web
Audio and Video Quality
Others
Legacy Documentation
RTC RoomEngine SDK(Old)
Integrating TUIRoom (Web)
Integrating TUIRoom (Android)
Integrating TUIRoom (iOS)
Integrating TUIRoom (Flutter)
Integrating TUIRoom (Electron)
TUIRoom APIs
On-Cloud Recording and Playback (Old)
RTC Analytics Monthly Packages (Previous Version)
Protocols and Policies
Compliance
Security White Paper
Notes on Information Security
Service Level Agreement
Apple Privacy Policy: PrivacyInfo.xcprivacy
TRTC Policy
Privacy Policy
Data Processing And Security Agreement
Glossary

Sending and Receiving Messages

PDF
Focus Mode
Font Size
Last updated: 2026-03-30 17:31:53

Overview

The TRTC SDK provides the ability to send custom messages. With this feature, any user whose role is an anchor can broadcast their own custom messages to other users in the same video room.

Supported Platforms

iOS
Android
Web
macOS
Windows
Electron
Flutter

How It Works

A user's custom message will be combined into the audio/video data streams and transmitted to other users in the same room alongside. As audio/video channels themselves are not completely reliable, in order to improve the reliability, the TRTC SDK implements a reliability guarantee mechanism internally.




Sending Messages

Messages are sent by calling the sendCustomCmdMsg API of TRTCCloud, and the following four parameters need to be specified during sending:
Parameter Name
Description
cmdID
Message ID. Value range: 1–10. Messages in different business types should use different cmdIDs.
data
Message to be sent, which can contain up to 1 KB (1,000 bytes) of data.
reliable
Whether reliable sending is enabled; if yes, the receiver needs to temporarily store the data of a certain period to wait for re-sending, which will cause certain delay.
ordered
Whether orderly sending is enabled, i.e., whether the data should be received in the same order in which it is sent; if yes, the receiver needs to temporarily store and sort messages, which will cause certain delay.
Note:
reliable and ordered must be set to the same value (YES or NO) and cannot be set to different values currently.
Objective-C
Java
C++
C#
Dart
Web
// Sample code for sending a custom message
- (void)sendHello {
// Command word for the custom message. A set of rules needs to be customized according to the business needs. 0x1 is used as an example to send a text broadcast message
NSInteger cmdID = 0x1;
NSData *data = [@"Hello" dataUsingEncoding:NSUTF8StringEncoding];
// `reliable` and `ordered` need to be consistent for now. Orderly sending is used as an example here
[trtcCloud sendCustomCmdMsg:cmdID data:data reliable:YES ordered:YES];
}


// Sample code for sending a custom message
public void sendHello() {
try {
// Command word for the custom message. A set of rules needs to be customized according to the business needs. 0x1 is used as an example to send a text broadcast message
int cmdID = 0x1;
String hello = "Hello";
byte[] data = hello.getBytes("UTF-8");
// `reliable` and `ordered` need to be consistent for now. Orderly sending is used as an example here
trtcCloud.sendCustomCmdMsg(cmdID, data, true, true);

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}


// Sample code for sending a custom message
void sendHello()
{
// Command word for the custom message. A set of rules needs to be customized according to the business needs. 0x1 is used as an example to send a text broadcast message

uint32_t cmdID = 0x1;
uint8_t* data = { '1', '2', '3' };
uint32_t dataSize = 3; // Length of data

// `reliable` and `ordered` need to be consistent for now. Orderly sending is used as an example here
trtcCloud->sendCustomCmdMsg(cmdID, data, dataSize, true, true);
}


// Sample code for sending a custom message
private void sendHello()
{
// Command word for the custom message. A set of rules needs to be customized according to the business needs. 0x1 is used as an example to send a text broadcast message

uint cmdID = 0x1;
byte[] data = { '1', '2', '3' };
uint dataSize = 3; // Length of data

// `reliable` and `ordered` need to be consistent for now. Orderly sending is used as an example here
mTRTCCloud.sendCustomCmdMsg(cmdID, data, dataSize, true, true);
}

try {
int cmdId = 0x1;
String hello = "hello";
_trtcCloud.sendCustomCmdMsg(cmdId, hello, true, true);
} catch (e) {
print(e);
}
const trtc = TRTC.create();
await trtc.enterRoom({ sdkAppId, userId, userSig, roomId: 12345 })
// send custom message
const data = new TextEncoder().encode('hello').buffer;
trtc.sendCustomMessage({ cmdId: 1, data });

Receiving Messages

After a user in a room uses sendCustomCmdMsg to send a custom message, other users in the room can receive the message through the onRecvCustomCmdMsg API in the SDK callback.
Objective-C
Java
C++
C#
Dart
Web
// Receive and process messages sent by other users in the room
- (void)onRecvCustomCmdMsgUserId:(NSString *)userId cmdID:(NSInteger)cmdId seq:(UInt32)seq message:(NSData *)message
{
// Receive the message sent by `userId`
switch (cmdId) // `cmdId` agreed upon between sender and receiver
{
case 0:
// Process the message with `cmdId` = 0
break;
case 1:
// Process the message with `cmdId` = 1
break;
case 2:
// Process the message with `cmdId` = 2
break;
default:
break;
}
}


// Inherit `TRTCCloudListener` and implement the `onRecvCustomCmdMsg` method to receive and process messages sent by others in the room
public void onRecvCustomCmdMsg(String userId, int cmdId, int seq, byte[] message) {
// Receive the message sent by `userId`
switch (cmdId) // `cmdId` agreed upon between sender and receiver
{
case 0:
// Process the message with `cmdId` = 0
break;
case 1:
// Process the message with `cmdId` = 1
break;
case 2:
// Process the message with `cmdId` = 2
break;
default:
break;

}


// Receive and process messages sent by other users in the room
void TRTCCloudCallbackImpl::onRecvCustomCmdMsg(
const char* userId, int32_t cmdId, uint32_t seq, const uint8_t* msg, uint32_t msgSize)
{
// Receive the message sent by `userId`
switch (cmdId) // `cmdId` agreed upon between sender and receiver
{
case 0:
// Process the message with `cmdId` = 0
break;
case 1:
// Process the message with `cmdId` = 1
break;
case 2:
// Process the message with `cmdId` = 2
break;
default:
break;
}
}


// Receive and process messages sent by other users in the room
public void onRecvCustomCmdMsg(string userId, int cmdId, uint seq, byte[] msg, uint msgSize)
{
// Receive the message sent by `userId`
switch (cmdId) // `cmdId` agreed upon between sender and receiver
{
case 0:
// Process the message with `cmdId` = 0
break;
case 1:
// Process the message with `cmdId` = 1
break;
case 2:
// Process the message with `cmdId` = 2
break;
default:
break;
}
}

TRTCCloudListener(
onRecvCustomCmdMsg: (userId, cmdId, seq, message) {

},
onMissCustomCmdMsg: (userId, cmdId, errCode, missed) {
}
);
// receive custom message
trtc.on(TRTC.EVENT.CUSTOM_MESSAGE, event => {
// event.userId: remote userId.
// event.cmdId: message cmdId.
// event.seq: message sequence number.
// event.data: custom message data, type is ArrayBuffer.
console.log(`received custom msg from ${event.userId}, message: ${new TextDecoder().decode(event.data)}`)
})

Use Limits

Since custom messages have a higher transmission priority than audio/video data, if too many of them are sent, audio/video data may be interfered with, resulting in video lagging or blurring. Therefore, the following frequency limits apply to custom messages:
As custom messages are broadcast to all users in the same room, up to 30 messages can be sent per second.
A data packet (i.e., data size) can be of up to 1 KB; if the threshold is exceeded, the packet is very likely to be discarded by the intermediate router or server.
A client can send up to 8 KB of data in total per second, that is, if each data packet is of 1 KB, up to 8 packets can be sent per second.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback