3

I´m trying to use the TeamSpeak SDK for a personal project, but the code I wrote gives me weird errors.
I read the documentation many times to find an error but I can´t see why my program is not able to connect to the TeamSpeak Server.

Here is the output from the program:

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

Here is the program code

#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();
}
James Fenwick
  • 2,190
  • 1
  • 20
  • 30

1 Answers1

0

It appears your client crashes immediately on connecting.

Here are some common causes to check:

  • Server doesn't exist at that address.
  • Server password is wrong.
  • Default channel doesn't exist.
  • Client has been banned.
  • Server is an illegal installation.
  • Security level of your identity is too low.

Also, this error can be triggered when a component such as client, server, etc need to be updated:

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.

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