Forum

Results 1 to 7 of 7
  1. #1
    Join Date
    November 2012
    Posts
    4

    Failed connection initialisation

    Hey guys,

    I just started programming with the client SDK and got a problem now:
    I can't connect to any server. After the status change to connecting, it changes to disconnected and there is a ERROR_failed_connection_initialisation error.
    ts3client_startConnection returns ERROR_ok.

    I don't know what I am doing wrong. I hope you can help me

    Code:
    // ts3bot.cpp
    #include "./ts3_sdk_3.0.2/include/clientlib.h"
    #include "./ts3_sdk_3.0.2/include/clientlib_publicdefinitions.h"
    #include "./ts3_sdk_3.0.2/include/public_definitions.h"
    #include "./ts3_sdk_3.0.2/include/public_errors.h"
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <fstream>
    using namespace std;
    
    
    bool ts3bot_running = true;
    
    
    unsigned int ts3bot_createIdentity(char** result) {
    	unsigned int error;
    	error = ts3client_createIdentity(result);
    	if (error != ERROR_ok) {
    		return error;
    	}
    	ofstream ts3bot_identity_file("ts3bot_identity.txt", ios::out | ios::trunc);
    	if (ts3bot_identity_file.is_open()) {
    		ts3bot_identity_file << *result;
    		ts3bot_identity_file.close();
    		error = ERROR_ok;
    	}
    	else {
    		error = ERROR_undefined; // Error writing in file
    	}
    	return error;
    }
    
    char* ts3bot_printErrorMessage(unsigned int* errorNumber) {
    	char* error;
    	if (ts3client_getErrorMessage(*errorNumber, &error) != ERROR_ok) {
    		string error_string = "Error getting error message (dafuq)";
    		error = new char[error_string.size()+1];
    		copy(error_string.begin(), error_string.end(), error);
    		error[error_string.size()] = '\0';
    	}
    	return error;
    }
    
    static void ts3bot_onConnectStatusChangeEvent_Callback(uint64 serverConnectionHandlerID, int newStatus, unsigned int errorNumber) {
    	cout << "new status: ";
    	if (newStatus == STATUS_DISCONNECTED) {
    		cout << "disconnected";
    	}
    	if (newStatus == STATUS_CONNECTING) {
    		cout << "connecting";
    	}
    	if (newStatus == STATUS_CONNECTED) {
    		cout << "connected";
    	}
    	if (newStatus == STATUS_CONNECTION_ESTABLISHING) {
    		cout << "connection establishing";
    	}
    	if (newStatus == STATUS_CONNECTION_ESTABLISHED) {
    		cout << "connection established";
    	}
    	if (errorNumber != ERROR_ok) {
    		cout << " (" << ts3bot_printErrorMessage(&errorNumber) << ")";
    	}
    	cout << endl;
    }
    
    static void ts3bot_onServerErrorEvent_Callback(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage) {
    	cout << "server sent error: " << errorMessage << " (" << ts3bot_printErrorMessage(&error) << ") - " << returnCode << " - " << extraMessage << endl;
    }
    
    
    int main( void ) {
    	unsigned int error;
    	
    	/* Create struct */
    	ClientUIFunctions clUIFuncs;
    	
    	/* Initialize all function pointers with NULL */
    	memset(&clUIFuncs, 0, sizeof(struct ClientUIFunctions));
    	
    	/* Assign implemented function pointers */
    	clUIFuncs.onConnectStatusChangeEvent = ts3bot_onConnectStatusChangeEvent_Callback;
    	clUIFuncs.onServerErrorEvent = ts3bot_onServerErrorEvent_Callback;
    	
    	/* Initialize client lib with callback function pointers */
    	error = ts3client_initClientLib(&clUIFuncs, NULL, LogType_CONSOLE, NULL, "/media/DEV/cpp/TS3-Bot/ts3_sdk_3.0.2/bin/");
    	if(error != ERROR_ok) {
    		cout << "Error initializing clientlib: " << ts3bot_printErrorMessage(&error) << endl;
    		return 0;
    	}
    	
    	/* Spawn new server connection handler */
    	uint64 serverConnectionHandlerID;
    	error = ts3client_spawnNewServerConnectionHandler(0, &serverConnectionHandlerID);
    	if (error != ERROR_ok) {
    		cout << "Error spawning new server connection handler: " << ts3bot_printErrorMessage(&error) << endl;
    		return 0;
    	}
    	
    	/* Get identity */
    	char* identity;
    	ifstream ts3bot_identity_file("ts3bot_identity.txt");
    	if (ts3bot_identity_file.is_open()) {
    		string identity_string;
    		getline(ts3bot_identity_file, identity_string);
    		ts3bot_identity_file.close();
    		identity = new char[identity_string.size()+1];
    		copy(identity_string.begin(), identity_string.end(), identity);
    		identity[identity_string.size()] = '\0';
    	}
    	else {
    		error = ts3bot_createIdentity(&identity);
    		if (error != ERROR_ok) {
    			cout << "Error creating identity: " << ts3bot_printErrorMessage(&error) << endl;
    			return 0;
    		}
    	}
    	
    	/* Connect to the server */
    	error = ts3client_startConnection(serverConnectionHandlerID, identity, "voice.teamspeak.com", 9987, "ts3bot", NULL, "", "");
    	if (error != ERROR_ok) {
    		cout << "Error connecting to the server: " << ts3bot_printErrorMessage(&error) << endl;
    	}
    	ts3client_freeMemory(identity);
    	
    	
    	
    	/* Wait for user input to continue */
    	string test;
    	getline(cin, test);
    	
    	
    	
    	/* Dissconnect */
    	error = ts3client_stopConnection(serverConnectionHandlerID, "");
    	if (error != ERROR_ok) {
    		cout << "Error disconnecting from the server: " << ts3bot_printErrorMessage(&error) << endl;
    	}
    	
    	/* Shut down */
    	error = ts3client_destroyServerConnectionHandler(serverConnectionHandlerID);
    	if (error != ERROR_ok) {
    		cout << "Error destroying server connection handler: " << ts3bot_printErrorMessage(&error) << endl;
    		return 0;
    	}
    	error = ts3client_destroyClientLib();
    	if (error != ERROR_ok) {
    		cout << "Error destroying clientlib: " << ts3bot_printErrorMessage(&error) << endl;
    		return 0;
    	}
    	
    	return 0;
    }
    Last edited by Horgar; November 25th, 2012 at 11:44 PM.

  2. #2
    Join Date
    November 2012
    Posts
    4
    same problem with the example of the sdk

  3. #3
    Join Date
    September 2012
    Posts
    6,080
    The SDK cannot connect to any regular server, but only to SDK servers.

  4. #4
    Join Date
    November 2012
    Posts
    4
    Bad..

    Can I use the server example as a regular server?

  5. #5
    Join Date
    September 2012
    Posts
    6,080
    The SDK and regular TeamSpeak versions are not interchangeable nor compatible with each other. That means that:
    The TeamSpeak 3 Client downloaded from our website can only connect to servers downloaded from our website.
    Any client created with the use of the SDK can only connect to servers which are created with the SDK.
    Any server created with the use of the SDK will only accept connections from clients created with the SDK.

  6. #6
    Join Date
    November 2012
    Posts
    4
    Ok.

    Do you know any other C/C++ libs that can query a regular teamspeak server?

  7. #7
    Join Date
    September 2012
    Posts
    6,080
    you can query any regular TeamSpeak 3 server through the server query interface if it is publicly accessible, there might even be wrappers / libs around so that you might not have to implement all the network stuff yourself.
    This obviously won't enable you to use voice though.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error connection initialisation
    By Samuwulf in forum Android
    Replies: 7
    Last Post: June 5th, 2014, 02:08 AM
  2. Connection Failed
    By winterrat in forum Client Support
    Replies: 0
    Last Post: January 1st, 2010, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •