Common causes of client join failures

更新时间:
复制 MD 格式

This topic describes common causes of client join failures and their solutions.

How to get parameters for joining a channel

You must obtain the parameters for joining a channel from your AppServer. For more information, see Use a token for authentication.

FAQ 1: Join failure on Windows due to non-UTF-8 encoding of the userName parameter

1. Problem description

When you retrieve a string using the Windows API or file read/write operations that do not specify an encoding, the system's default ANSI encoding might be used. For Simplified Chinese versions of Windows, this is typically GBK or GB2312. For Traditional Chinese versions, it might be Big5. The `JoinChannel` interface of the Windows software development kit (SDK) requires the `userName` parameter to be in UTF-8 format. If you pass a non-UTF-8 string, parsing fails and the client cannot join the channel.

2. Sample code for UTF-8 string conversion

#include <windows.h>
#include <string>
#include <iostream>

// Converts a multi-byte string to a wide character string
std::wstring MultiByteToWideChar(const std::string& mbStr, UINT codePage) {
    if (mbStr.empty()) return L"";

    int wlen = MultiByteToWideChar(codePage, 0, &mbStr[0], (int)mbStr.size(), NULL, 0);
    wchar_t* wszGBK = new wchar_t[wlen + 1];
    memset(wszGBK, 0, (wlen + 1) * sizeof(wchar_t));
    MultiByteToWideChar(codePage, 0, &mbStr[0], (int)mbStr.size(), wszGBK, wlen);

    std::wstring result(wszGBK);
    delete[] wszGBK;
    return result;
}

// Converts a wide character string to UTF-8
std::string WideCharToMultiByte(const std::wstring& wstr) {
    if (wstr.empty()) return "";

    int mblen = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
    char* pMB = new char[mblen + 1];
    memset(pMB, 0, (mblen + 1) * sizeof(char));
    WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), pMB, mblen, NULL, NULL);

    std::string result(pMB);
    delete[] pMB;
    return result;
}

// Main function
int main() {
    // Example user input
    std::string input = "Hello, World";  // Replace this with the actual method for getting user input

    // Get the current system's ANSI code page
    UINT ansiCodePage = GetACP();

    // Convert the input to wide characters
    std::wstring wideInput = MultiByteToWideChar(input, ansiCodePage);

    // Convert the wide characters back to UTF-8 encoding
    std::string utf8Output = WideCharToMultiByte(wideInput);

    // Print the result
    std::cout << "Original: " << input << "\n";
    std::cout << "UTF-8: " << utf8Output << "\n";

    return 0;
}

FAQ 2: Join failure due to a token error

1. Generate and verify a temporary token in the console

  • Fill in the client code with the new token and related fields. The following Android code provides an example:

DingRtcAuthInfo auth = new DingRtcAuthInfo();
auth.channelId = /* Channel ID */;
auth.appId = /* Application ID */;
auth.token = /* Channel authentication token */;
auth.userId = /* User ID */;
  • Execute `joinChannel` and check the notification from the `onJoinChannelResult` callback function.

    If the result is 0, the client successfully joined the channel. Before you resolve the token issue, you can use the temporary token to continue developing and debugging client features. Then, proceed to Step 2 for further troubleshooting.

    If the result is not 0, the client failed to join the channel. In this case, confirm that you are using the correct AppKey. Check if the `appId`, `channelId`, `userId`, or `token` values were altered during copying, for example, by adding extra spaces. If you still cannot find the cause, extract the client log file as described in Step 3 and contact your account manager or submit a ticket for further investigation.

2. Generate and verify a token using server-side code

  • Record the AppID, channel ID, user ID, and token generated by your code.

The following code shows an example of token generation in Java.

Note:

1) For the Java code, see https://gitee.com/dingrtc/AliRTCSample/blob/master/Server/java/src/main/java/com/company/apptoken/model/AppToken.java

2) For other languages, go to https://gitee.com/dingrtc/AliRTCSample/tree/master/Server and find the AppToken file for your language.

If the validation is successful, the token generated by the server is correct. If the client still cannot join the channel, extract the client log file as described in Step 3 and contact your account manager or submit a ticket for further investigation.

If the validation fails, the token generated by the server is incorrect. The server-side developer must investigate the issue. Possible causes include the following:

  • A token generated with a v2.0 AppID/AppKey is used with a v3.0 client SDK.

  • The AppID or AppKey is incorrect. For example, extra spaces or other characters were added during copying, or the AppKey for a different AppID was used.

  • The token is incorrect. For example, the token was altered by auto wrap in a text editor during copying.

  • The timestamp value exceeds the maximum validity period. The maximum validity period is 24 hours. If you set the timestamp to a 25-hour validity period, the token will be invalid ((System.currentTimeMillis() / 1000) + 25 * 60 * 60).

  • The timestamp has expired. For example, if a token is generated at 12:00 on January 1 with a 12-hour validity period ((System.currentTimeMillis() / 1000) + 12 * 60 * 60), it will expire if used at 01:00 on January 2.

3. Extract RTC SDK log files for Alibaba Cloud engineers

If a temporary token from the console is invalid, or if a server-generated token passes validation but the client still cannot join the channel, submit a ticket for further analysis. You must extract the local log files from the RTC SDK to help Alibaba Cloud engineers investigate the issue.

Platform

Default path

Android

/sdcard/Android/data/com.xxx.xxx/files/dingrtc/log

iOS

AppData/Library/Caches/dingrtc/log

Mac

Same folder as the executable file

Windows

%homepath%/dingrc/log

Note:

A log file directory name looks like this: `dingrtc_2024-11-25T224457218`

Common error codes for join failures

Error code (decimal)

Description

16974338

Server-side authentication failed. Troubleshoot the issue based on the instructions above.

33620485

Failed to join the channel: The token is invalid. Generate a new channel authentication token. For more information, see Use a token for authentication.

84148226

  • The user account has an overdue payment.

  • The user's token has expired. You can check this using the `timestamp` parameter.

  • The `appid` or `appkey` is incorrect or they do not match. Each `appid` corresponds to a unique `appkey`.

  • The user's authentication parameters are incorrect.

For more information, see Use a token for authentication.