anyKode Marilou
ContentsIndexHome
PreviousUpNext
Connection::Connect (const xkode::lib::String &, int, bool)

Connection avec le serveur TCP MODA.

C++
bool Connect(const xkode::lib::String & ServerIP, int TCPPort, bool PerformSimulationReset);
Parameters 
Description 
const xkode::lib::String & ServerIP 
[in] Adresse IP ou nom du serveur MODA. 
int TCPPort 
[in] Port TCP du serveur. Si TCPPort vaut 0, c'est le port par défaut 13000 qui est utilisé. 
bool PerformSimulationReset 
[in] Indique si Exec doit faire un reset de la simulation. 

true si la connection a pu être établie, false sinon. Dans ce dernier cas, vérifier que le serveur MODA est démarré et que le port du serveur n'est pas bloqué par un firewall. Par défaut il s'agit du port 13000 (TCP et UDP).

//////////////////////////////////////////////////////////////////
//Dynamic port and server sample
//////////////////////////////////////////////////////////////////
#include "Modacpp.h"
#include "conio.h"

#define SIMULATEDROBOT "/robot1"
#define MODASERVER "localhost"

int main(int argc, CHAR* argv[])
{
//process the command line
CommandLine::ProcessCommandLine(argc,argv);
//Connect to MODA server
Connection *pConnection=new ModaCPP::Connection(true);
if(pConnection->Connect( CommandLine::GetArgumentValue("/modaserver","127.0.0.1"),CommandLine::GetArgumentValueINT("/modaport",0),false))
    {
    _cprintf("Connection ok\r\n");
    ModaCPP::RobotPHX *robot=connection->QueryRobotPHX(SIMULATEDROBOT);
    if(robot)
        {
        cprintf("robot found\r\n");
        }
    else
        {
        cprintf("robot not found\r\n");
        }
    }
else
    {
    cprintf("Unable to connect to moda server : be sure Exec is running and MODA TCP/UDP ports are open\r\n");
    }
connection->Disconnect();
return 0;
}


//////////////////////////////////////////////////////////////////
//Fixed port and server sample
//////////////////////////////////////////////////////////////////
#include "Modacpp.h"
#include "conio.h"

#define SIMULATEDROBOT "/robot1"
#define MODASERVER "localhost"

int main(int argc, CHAR* argv[])
{
ModaCPP::Connection *connection=new ModaCPP::Connection(true);
if(connection->Connect(MODASERVER))
    {
    _cprintf("Connexion to %s ok\r\n",MODASERVER);
    ModaCPP::RobotPHX *robot=connection->QueryRobotPHX(SIMULATEDROBOT);
    if(robot)
        {
        cprintf("robot found\r\n");
        }
    else
        {
        cprintf("robot not found\r\n");
        }
    }
else
    {
    cprintf("Unable to connect to moda server : be sure Exec is running and MODA TCP/UDP ports are open\r\n");
    }
connection->Disconnect();
return 0;
}
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
What do you think about this topic? Send feedback!