diff --git a/simulators/c++2/src_simulator/main.h b/simulators/c++2/src_simulator/main.h index 0b5b96d25a4da7297b3ee867266f41860fd0a14b..f0b16b0ca663612a6692d926055f51896c45546f 100644 --- a/simulators/c++2/src_simulator/main.h +++ b/simulators/c++2/src_simulator/main.h @@ -74,7 +74,7 @@ int main(int len, char ** args) { gettimeofday(&end,NULL); // std::cout << "The preparation took " << getTimeDiff(begin,end) << "usec.\n"; - std::string arr[] = {"-gname", "-gpath", "-server", "-file", "-explo", "-signals", "-helpserver", "-helpcommand", "-help", "-cmd", "-ohtml", + std::string arr[] = {"-gname", "-gpath", "-server", "-port", "-file", "-explo", "-signals", "-helpserver", "-helpcommand", "-help", "-cmd", "-ohtml", "-otxt", "-ovcd", "-ograph", "-oxml"}; std::vector<std::string> validCmds(arr, arr + sizeof(arr)/sizeof(arr[0])); for (int k = 0; k < len; k++) { diff --git a/simulators/c++2/src_simulator/sim/Server.cpp b/simulators/c++2/src_simulator/sim/Server.cpp index 6d73b6752dfc7c57531583570f51aacc4610d6ea..46e06964b5c8ebb9e4a9a39a8022a64bf656451c 100644 --- a/simulators/c++2/src_simulator/sim/Server.cpp +++ b/simulators/c++2/src_simulator/sim/Server.cpp @@ -46,20 +46,27 @@ Server::Server():_socketClient(-1){ pthread_mutex_init(&_replyMutex, NULL); } +Server::Server(std::string iNewPort):_socketClient(-1){ + _portServer = iNewPort; + pthread_mutex_init(&_replyMutex, NULL); +} + int Server::run(){ int aSocketServer=0; // listen on aSocketServer, client connection on _socketClient struct addrinfo aHints; //aHints for getaddrinfo struct addrinfo *aServerInfo; //information about the server, created by getaddrinfo struct sockaddr_storage aClientAddrInfo;// connector's address information int aRetVal; //return value for getaddrinfo + const char* aPortServer; // port server for getaddrinfo memset(&aHints, 0, sizeof aHints); aHints.ai_family = AF_UNSPEC; aHints.ai_socktype = SOCK_STREAM; aHints.ai_flags = AI_PASSIVE; // use my IP + aPortServer = ((_portServer != ""))? _portServer.c_str(): PORT; //get address information about server: getaddrinfo(hostname, port, hints, result) - if ((aRetVal = getaddrinfo(NULL, PORT, &aHints, &aServerInfo)) != 0) { + if ((aRetVal = getaddrinfo(NULL, aPortServer, &aHints, &aServerInfo)) != 0) { std::cerr << "getaddrinfo: " << gai_strerror(aRetVal) << std::endl; return 1; } diff --git a/simulators/c++2/src_simulator/sim/Server.h b/simulators/c++2/src_simulator/sim/Server.h index f8927916043597b56fc7376ee61e86e0ecb927a0..fba3976ab7d544bbd7f3fd37e342ab4fbec781af 100644 --- a/simulators/c++2/src_simulator/sim/Server.h +++ b/simulators/c++2/src_simulator/sim/Server.h @@ -51,6 +51,7 @@ class Server: public ServerIF{ public: ///Constructor Server(); + Server(std::string iNewPort); ///Run the server int run(); void sendReply(std::string iReplyStr); @@ -68,6 +69,8 @@ protected: void* get_in_addr(struct sockaddr *sa) const; ///pointer to synchronization structure int _socketClient; + ///Defines a specific port + std::string _portServer; ///Mutex protecting the reply function of the Server pthread_mutex_t _replyMutex; }; diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index 2e96758092e1e3aa042e2ca8f1ad55b988e6f44a..0114352a3912706997e6d48675a5fbb215fe5e7b 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -1249,6 +1249,7 @@ void Simulator::printHelp(){ std::cout << "\n************************** Command line arguments ******************************************\n" "-gpath specify path for graph output\n" "-server launch simulator in server mode\n" + "-port specify a port in which the simulator will be launched\n" "-helpserver print all available commands\n" "-helpcommand cmd print all information about cmd\n" "-file read simulation commands from file\n" @@ -1333,7 +1334,15 @@ ServerIF* Simulator::run(int iLen, char ** iArgs){ _graphOutPath+="/"; aArgString =getArgs("-server", "server", iLen, iArgs); - if (!aArgString.empty()) return new Server(); + if (!aArgString.empty()) { + aArgString =getArgs("-port", "", iLen, iArgs); + if (!aArgString.empty()) { + return new Server(aArgString); + } + else { + return new Server(); + } + } aArgString =getArgs("-file", "file", iLen, iArgs); if (!aArgString.empty()) return new ServerLocal(aArgString);