gpt4 book ai didi

c++ - TeamSpeak 3 SDK 连接问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:21:59 28 4
gpt4 key购买 nike

我尝试将 TeamSpeak SDK 用于个人项目,但我编写的代码出现了奇怪的错误。
我多次阅读文档以发现错误,但我不明白为什么我的程序无法连接到 TeamSpeak 服务器。

这是程序的输出:

Client library version: 3.0.3.2 [Build: 1433933257] SDK
Connection Status changed to: 1, errorNumber: 0
Connection Status changed to: 0, errorNumber: 1797
failed connection initialization

这是程序代码

#include <iostream>
#include <fstream>
#include <cstring>
#include <teamspeak/clientlib.h>
#include <teamspeak/public_errors.h>

uint64 connectionHandler;

void destroy();

void event_connectStatusChanged(uint64 serverConnectionIDHandler, int newStatus, unsigned int errorNumber);
void event_serverError(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage);

int main()
{
ClientUIFunctions uiFunctions;
memset(&uiFunctions, 0, sizeof(struct ClientUIFunctions));

uiFunctions.onConnectStatusChangeEvent = event_connectStatusChanged;
uiFunctions.onServerErrorEvent = event_serverError;

unsigned int error = ts3client_initClientLib(&uiFunctions, NULL, LogType_FILE, NULL, "./");

if (error != ERROR_ok)
printf("Error initializing clientlib: %i\n", error);

char* version;
error = ts3client_getClientLibVersion(&version);
if (error != ERROR_ok) {
printf("Error querying clientlib version: %d\n", error);
return 0;
}

printf("Client library version: %s\n", version); /* Print version */
ts3client_freeMemory(version); /* Release string */

if (ts3client_spawnNewServerConnectionHandler(0, &connectionHandler) != ERROR_ok)
{
destroy();
return 0;
}

char* identity;
ts3client_createIdentity(&identity);
error = ts3client_startConnection(connectionHandler, identity, "127.0.0.1", 9987, "test", NULL, "", "");
ts3client_freeMemory(identity);

if (error != ERROR_ok)
std::cout << "Connection failed!" << std::endl;

getchar();

ts3client_stopConnection(connectionHandler, "...");

destroy();
return 0;
}

void event_connectStatusChanged(uint64 serverConnectionIDHandler, int newStatus, unsigned int errorNumber)
{
printf("Connection Status changed to: %i, errorNumber: %i\n", newStatus, errorNumber);
if (errorNumber != ERROR_ok)
{
char* error;
ts3client_getErrorMessage(errorNumber, &error);
std::cout << error << std::endl;
ts3client_freeMemory(error);
}
}

void event_serverError(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage)
{
std::cout << "ERROR: " << errorMessage << std::endl << "Extra Message: " << extraMessage << std::endl;
}

void destroy()
{
ts3client_destroyServerConnectionHandler(connectionHandler);
ts3client_destroyClientLib();
}

最佳答案

您的客户端似乎在连接时立即崩溃。

以下是一些需要检查的常见原因:

  • 该地址不存在服务器。
  • 服务器密码错误。
  • 默认 channel 不存在。
  • 客户已被禁止。
  • 服务器是非法安装。
  • 您身份的安全级别太低。

此外,当客户端、服务器等组件需要更新时,也会触发此错误:

I updated to the latest version because the bot wouldn't launch and figured I'd give the install on my other server another try. It's working flawlessly now.

引用:https://forum.sinusbot.com/threads/new-connection-status-0-error-1797.2508/

关于c++ - TeamSpeak 3 SDK 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36251685/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com