# User channels (/en/realtime-media/rtm/build/work-with-channels/user-channel/macos)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Signaling enables you to send direct, point-to-point messages to individual users through user channels. This feature is useful in one-on-one communication use-cases such as private chats and customer support interactions.

    ## Understand the tech [#understand-the-tech-3]

    To implement point-to-point communication between individual users in your app:

    1. **Set up the Signaling SDK**: [Integrate the Signaling SDK](/en/realtime-media/rtm/quickstart) in your app and [initialize an instance](/en/realtime-media/rtm/quickstart) of the Signaling client.
    2. **Authenticate the user**: [Log in to Signaling](/en/realtime-media/rtm/quickstart) using a unique user ID.
    3. **Send direct messages**: Call the `publish` method with the User channel type and specify the recipient's user ID as the channel name to send direct messages.
    4. **Handle incoming messages**: [Listen for message events](/en/realtime-media/rtm/quickstart) to receive messages sent directly to the local user.

    ## Prerequisites [#prerequisites-3]

    Ensure that you have:

    * Integrated the Signaling SDK in your project, and implemented the framework functionality from the [SDK quickstart](/en/realtime-media/rtm/quickstart).

    ## Implement user messages [#implement-user-messages-3]

    This section shows you how to use the Signaling SDK to send messages directly to a specified user.

    In a user channel, you send a point-to-point message to a specified user by calling the `publish` method. Set the `channelType` parameter to `user` and the `channelName` parameter to the user ID of the specified user. This method enables you to send messages to one user at a time. While Signaling does not limit the number of users you can send messages to or receive messages from, it does [limit](/en/realtime-media/rtm/reference/limitations) the frequency at which you can send messages to users.

    Refer to the following sample code for sending messages:

    **String message**

    <CodeBlockTabs defaultValue="Swift">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Swift">
          Swift
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Objective-C">
          Objective-C
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Swift">
        ```swift  tabGroup="language"
        let message = "Hello Agora!"
            let user = "Tony"

            let publishOption = AgoraRtmPublishOptions()
            publishOption.channelType = .user

            rtm.publish(channelName: user, message: message, option: publishOption, completion: { res, error in
                if error != nil {
                    print("\(error?.operation) failed! error reason is \(error?.reason)")
                } else {
                    print("success")
                }
            })
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Objective-C">
        ```objc  tabGroup="language"
        // Send string message
            NSString* message = @"Hello Agora!";
            NSString* user = @"Tony";

            AgoraRtmPublishOptions* publish_option = [[AgoraRtmPublishOptions alloc] init];
            publish_option.channelType = AgoraRtmChannelTypeUser;

            [rtm publish:user message:message option:publish_option completion:^(AgoraRtmCommonResponse * _Nullable response, AgoraRtmErrorInfo * _Nullable errorInfo) {
                if (errorInfo == nil) {
                    NSLog(@"publish success!!");
                } else {
                    NSLog(@"publish failed, errorCode %d, reason %@", errorInfo.errorCode, errorInfo.reason);
                }
            }];
        ```
      </CodeBlockTab>
    </CodeBlockTabs>

    **Binary message**

    <CodeBlockTabs defaultValue="Swift">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Swift">
          Swift
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Objective-C">
          Objective-C
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Swift">
        ```swift  tabGroup="language"
        let bytes: [UInt8] = [ /* your raw values */ ]
            let rawMessage = Data(bytes: bytes, count: bytes.count)

            streamChannel.publish(channelName: user, data: rawMessage, option: nil) { response, errorInfo in
                if errorInfo == nil {
                    print("publish success!!")
                } else {
                    print("publish failed, errorCode \(errorInfo!.errorCode), reason \(errorInfo!.reason)")
                }
            }
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Objective-C">
        ```objc  tabGroup="language"
        // Send string message
            NSString* message = @"Hello Agora!";
            NSString* user = @"Tony";

            AgoraRtmPublishOptions* publish_option = [[AgoraRtmPublishOptions alloc] init];
            publish_option.channelType = AgoraRtmChannelTypeUser;

            [rtm publish:user message:message option:publish_option completion:^(AgoraRtmCommonResponse * _Nullable response, AgoraRtmErrorInfo * _Nullable errorInfo) {
                if (errorInfo == nil) {
                    NSLog(@"publish success!!");
                } else {
                    NSLog(@"publish failed, errorCode %d, reason %@", errorInfo.errorCode, errorInfo.reason);
                }
            }];
        ```
      </CodeBlockTab>
    </CodeBlockTabs>

    <CalloutContainer type="info">
      <CalloutDescription>
        Signaling currently supports only string and binary message formats. To send other types of data such as JSON objects, or data from third-party data construction tools such as protobuf, serialize the data before sending the message. For information on how to effectively construct the payload data structure and recommended serialization methods, refer to [Message payload structuring](/en/realtime-media/rtm/build/send-and-receive-messages/message-payload-structuring).
      </CalloutDescription>
    </CalloutContainer>

    ## Reference [#reference-3]

    This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

    ### Message packet size [#message-packet-size-2]

    Signaling SDK imposes 32 KB size limits on message payload packets sent in user channels. The message payload packet size includes the message payload itself plus the size of the `customType` field. If the message payload package size exceeds the limit, you receive the following error message.

    <CodeBlockTabs defaultValue="Swift">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Swift">
          Swift
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Objective-C">
          Objective-C
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Swift">
        ```objc  tabGroup="language"
        // errorInfo
        {
            errorInfo.errorCode = rrorCode = .channelMessageLengthExceedLimitation
            errorInfo.reason = "Publish too long message."
            errorInfo.operation = "publish"; // or "publishTopicMessage
        }
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Objective-C">
        ```objc  tabGroup="language"
        // errorInfo
        {
            errorInfo.errorCode = AgoraRtmErrorChannelMessageLengthExceedLimitation;
            errorInfo.reason = @"Publish too long message.";
            errorInfo.Operation = @"publish"; // or "publishTopicMessage"
        }
        ```
      </CodeBlockTab>
    </CodeBlockTabs>

    To avoid sending failure due to excess message payload packet size, check the packet size before sending.

    ### API reference [#api-reference-3]

    **Swift**

    * [`publish`](/en/api-reference/api-ref/signaling?platform=objc\&tab=swift#messagepublishpropsag_platform)
    * [Receive](/en/api-reference/api-ref/signaling?platform=objc\&tab=swift#receive)

    **Objective-C**

    * [`publish`](/en/api-reference/api-ref/signaling?platform=ios\&tab=objc#messagepublishpropsag_platform)
    * [Receive](/en/api-reference/api-ref/signaling?platform=ios\&tab=objc#receive)

    
  
      
  
      
  
      
  
