コード例 #1
0
bool NetworkTest::Run(int argc, char** argv) {
    QString arg2;
    if(argc > 2)
        arg2 = argv[2];
    if(arg2 != "server" && arg2 != "client") {
        std::cerr << "Usage: ./test_framework Network < server | client >" << std::endl;
        return false;
    }

    dt::Root& root = dt::Root::GetInstance();
    root.Initialize(argc, argv);

    // register event prototype
    std::shared_ptr<dt::NetworkEvent> ptr(new CustomNetworkEvent(0, CustomNetworkEvent::CLIENT));
    root.GetNetworkManager()->RegisterNetworkEventPrototype(ptr);

    bool result = false;
    if(arg2.toLower() == "server") {
        result = RunServer();
    } else if(arg2.toLower() == "client") {
        result = RunClient();
    } else {
        std::cerr << "This should not happen." << std::endl;
        result = false;
    }

    root.Deinitialize();
    return result;
}
コード例 #2
0
//---------------------------------------------------------------------------
// Public Methods
//---------------------------------------------------------------------------
int RunClientServerTest()
{

	int ret;

	printf("Starting Client/Server test...\n\n");

	
	// Print out menu
	printf("Is this the client or server?\n");
	printf("Server = 0\n");
	printf("Client = 1\n");

	// Get input from user
	char input;
	scanf("%c%*c", &input);

	switch(input)
	{
		case '0': ret = RunServer(); break;
		case '1': ret = RunClient(); break;
		default: assert(false); break;
	}
	
	
	return ret;
}
コード例 #3
0
int main() {
	unsigned short port = 1337;
	string selection;
	string p;
	string ip = "localhost";

	cout << "NETWORK TEST - CLIENT-SERVER" << endl;

	cout << "Wanna launch a client (c) or a server (s) ?" << endl;
	getline(cin, selection);

	cout << "Which port ?" << endl;
	getline(cin, p);
	port = atoi(p.c_str());

	if(selection == "s") {

		RunServer(port);
	}

	else {
		cout << "Which IP?" << endl;
		getline(cin, ip);
		cout << "Connecting to " << ip << ":" << port << endl;

		RunClient(ip, port);
	}
}
コード例 #4
0
ファイル: daemon_test.cpp プロジェクト: Redi0/myCpp11Study
int main(int argc, char *argv[])
{
	RunServer(false);

	getchar();
	return 0;
}
コード例 #5
0
int main() {
	unsigned short port = 1337;
	char selection;
	string ip = "localhost";

	cout << "NETWORK TEST - CLIENT-SERVER" << endl;

	cout << "Wanna launch a client (c) or a server (s) ?" << endl;
	cin >> selection;

	cout << "Which port ?" << endl;
	cin >> port;

	if(selection == 's') {

		RunServer(port);
	}

	else {
		cout << "Which IP?" << endl;
		cin >> ip;
		cout << "Connecting to " << ip << ":" << port << endl;

		RunClient(ip, port);
	}
}
コード例 #6
0
EXPORT_C GLDEF_C TInt CAlwaysOnlineManagerServer::ThreadFunction( TAny* aParameters )
	{
    KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::ThreadFunction");
	TOAManagerStartupSignaller* parameters = static_cast<TOAManagerStartupSignaller*>(aParameters);
	TInt retVal = RunServer(*parameters);
    KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::ThreadFunction");
	return retVal;
	}	
コード例 #7
0
GLDEF_C TInt E32Main()

// Server process entry-point
// Recover the startup parameters and run the server

{
    TInt r = RunServer();
    return r;
}
コード例 #8
0
//-------------------------------------------------------------------------------
// Function Name : E32Main()
// Description   : Entry point for the server process.
//				   
//-------------------------------------------------------------------------------	
TInt E32Main()
	{
	TInt ret = KErrNoMemory;
	CTrapCleanup* cleanup = CTrapCleanup::New();
	if (cleanup)
		{
		ret = RunServer();
		delete cleanup;
		}
	return ret;
	}
コード例 #9
0
int main(int argc, char* argv[])
{
    std::cout << "Program Usage:\n";
    std::cout << argv[0] << " <0 = server, 1,2,..254 = client>\n";
    if(argc > 1)
    {
        if(atoi(argv[1]) == 0)
        {
            return RunServer();
        }
        else
        {
            return RunClient(gSubsystemID, (JAUS::Byte)(atoi(argv[1])) + 1);
        }
    }
    else
    {
        // Default
        return RunServer();
    }
    return 0;
}
コード例 #10
0
ファイル: servermain.c プロジェクト: Nalin-x-Linux/tuxmath
int main(int argc, char** argv)
{
    int ret;
#ifdef HAVE_LIBSDL_NET
    //Initialize a copy of mathcards to hold settings:
    lan_game_settings = (MC_MathGame*) malloc(sizeof(MC_MathGame));
    if (lan_game_settings == NULL)
    {
        fprintf(stderr, "\nUnable to allocate MC_MathGame\n");
        exit(1);
    }
    lan_game_settings->math_opts = NULL;
    if (!MC_Initialize(lan_game_settings))
    {
        fprintf(stderr, "\nUnable to initialize MathCards\n");
        exit(1);
    }
    //Initialize SDL and SDL_net:
    if(SDL_Init(0) == -1)
    {
        fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
        return 0;;
    }
    if (SDLNet_Init() < 0)
    {
        fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
        return 0;
    }

    /* Run actual program: */
    ret = RunServer(argc, argv);
    /* cleanup */
    SDLNet_Quit();
    SDL_Quit();
    if (lan_game_settings)
    {
        MC_EndGame(lan_game_settings);
        free(lan_game_settings);
        lan_game_settings = NULL;
    }
    return ret;
#else
    return 0;
#endif
}
コード例 #11
0
int main(int argc, char* argv[])
{
    const char*     configPath = "/system/etc/mountd.conf";
    int             i;    

    for (i = 1; i < argc; i++)
    {
        const char* arg = argv[i];
        
        if (strcmp(arg, "-f") == 0)
        {
            if (i < argc - 1)
                configPath = argv[++i];
        }
    }
        
    ReadConfigFile(configPath);
    StartAutoMounter();
    return RunServer();
}
コード例 #12
0
ファイル: main.cpp プロジェクト: M-Vivek/jvsim
int
main (int argc, char * argv[])
{
    // Get all command line options
    AgentServerCmdOptions opts;
    if (!opts.parseArgs(argc, argv)) {
        exit(0);
    }

    // Log file and config file pointers
    char *log_file;
    char *ini_config_file;

    // If ini file is defined, invoke Global Config Parser
    ini_config_file = opts.getIniConfigFile();
    if (ini_config_file != NULL) {
        bool parse_status = GlobalConfig::parse(std::string(ini_config_file),
                                                global_config);
        if (!parse_status) {
            std::cerr << "INI config file parse failed" << std::endl;
            exit(0);
        }

        // Set logger information
        std::string log_file_str = global_config.grpc_log_file_path + "/" +
                                   global_config.grpc_log_file_name;
        opts.setLogFile(log_file_str);

        // Set system mode information
        if (global_config.system_mode == SYSTEM_MODE_PROC) {
            opts.setProcMode(true);
        } else if (global_config.system_mode == SYSTEM_MODE_FILE) {
            opts.setFileMode(true);
            std::string file_str = global_config.system_file_path + "/" +
                                   global_config.system_file_name;
            opts.setFileName(file_str);
        } else {
            opts.setNullMode(true);
        }
    }

    // Validate if logger file was specified
    log_file = opts.getLogFile();
    if (log_file == NULL) {
        char *env_rp = std::getenv("ROOTPATH");
        if (env_rp != NULL) {
            // if ROOTPATH env variable is set, set default log path
            std::string log_file_str = (std::string)env_rp +
                                       "/logs/" + AGENTSERVER_LOGFILE;
            log_file = (char *)log_file_str.c_str();
            std::cout << "Log file not specified using -l option. " <<
                         "Default = " << log_file << std::endl;
        } else {
            std::cerr << "Please setup ROOTPATH environment variable " <<
                         "or use -l to set log file." << std::endl;
            exit(0);
        }
    }

    // Create a logger
    AgentServerLog *logger;
    logger = new AgentServerLog(log_file);
    logger->enable();

    // Pid check for on-box mode
    if (global_config.running_mode == RUNNING_MODE_ON_BOX){
        if (pid_lock(NA_GRPCD_PID, logger) < 0) {
            logger->log("Already running. Check pid. Terminating");
            exit(0);
        }
    }

    // Initialize interface with Mosquitto Library
    mosqpp::lib_init();

    // Initialize all the oc translators
    lib_oc_init();
    OpenConfig::display(logger);

    // Create a handle for the system
    AgentSystem *sys_handle = CreateSystemHandle(&opts, logger);

    // On start up/restart execute necessary functionality
    if (!on_startup(logger, sys_handle)) {
        logger->log("Failed in startup module. Terminating");
        exit(0);
    }

    // Create a PathValidator object
    PathValidator *path_validator = NULL;
    if (global_config.validate_ocpaths) {
        path_validator = new PathValidator(logger);
        bool status = path_validator->build_path_information_db(
                                    global_config.ocpath_file_path + "/" +
                                    global_config.ocpath_file_name);
        if (!status) {
            logger->log("PathValidator build_path failed. Terminating");
            exit(0);
        }
        path_validator->print_path_information_db();
    }

    // Start a UDP thread if requested
    if (global_config.udp_server_module) {
        udpreceiver = new UdpReceiver(logger,
                                      std::stoi(global_config.udp_server_ip),
                                      global_config.udp_server_port);
        std::thread udpreceiverthread([]() { (*udpreceiver)(); });
        udpreceiverthread.detach();
    }

    // Start the server
    RunServer(logger, sys_handle, path_validator);
}
コード例 #13
0
/*********************************************************************
* Function:        void BerkeleyTCPServerDemo(void)
*
* PreCondition:    Stack is initialized
*
* Input:           None
*
* Output:          None
*
* Side Effects:    None
*
* Overview:        None
*
* Note:            None
********************************************************************/
void BerkeleyTCPServerDemo(void)
{
    static SOCKET bsdServerSocket;
    static SOCKET ClientSock[MAX_CLIENT];
    struct sockaddr_in addr;
    struct sockaddr_in addRemote;
    int addrlen = sizeof(struct sockaddr_in);
    char bfr[64];
    int length;
    int i;
    int ClientsCnt = 0;
    BYTE res = STR_OK;
    static enum
    {
        BSD_INIT = 0,
        BSD_CREATE_SOCKET,
        BSD_BIND,
        BSD_LISTEN,
        BSD_OPERATION
    } BSDServerState = BSD_INIT;

    switch(BSDServerState)
    {
    case BSD_INIT:
        // Initialize all client socket handles so that we don't process
        // them in the BSD_OPERATION state
        for(i = 0; i < MAX_CLIENT; i++) {
            ClientSock[i] = INVALID_SOCKET;
        }
        BSDServerState = BSD_CREATE_SOCKET;
        ProtocolInit();
    // No break needed

    case BSD_CREATE_SOCKET:
        // Create a socket for this server to listen and accept connections on
        bsdServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if(bsdServerSocket == INVALID_SOCKET)
            return;

        BSDServerState = BSD_BIND;
    // No break needed

    case BSD_BIND:
        // Bind socket to a local port
        addr.sin_port = PORTNUM;
        addr.sin_addr.S_un.S_addr = IP_ADDR_ANY;
        if( bind( bsdServerSocket, (struct sockaddr*)&addr, addrlen ) == SOCKET_ERROR )
            return;

        BSDServerState = BSD_LISTEN;
    // No break needed

    case BSD_LISTEN:
        if(listen(bsdServerSocket, MAX_CLIENT) == 0)
            BSDServerState = BSD_OPERATION;

    // No break.  If listen() returns SOCKET_ERROR it could be because
    // MAX_CLIENT is set to too large of a backlog than can be handled
    // by the underlying TCP socket count (TCP_PURPOSE_BERKELEY_SERVER
    // type sockets in TCPIPConfig.h).  However, in this case, it is
    // possible that some of the backlog is still handleable, in which
    // case we should try to accept() connections anyway and proceed
    // with normal operation.

    case BSD_OPERATION:
        for(i=0; i<MAX_CLIENT; i++)
        {
            // Accept any pending connection requests, assuming we have a place to store the socket descriptor
            if(ClientSock[i] == INVALID_SOCKET)
                ClientSock[i] = accept(bsdServerSocket, (struct sockaddr*)&addRemote, &addrlen);

            // If this socket is not connected then no need to process anything
            if(ClientSock[i] == INVALID_SOCKET) {
                continue;
            }

            // For all connected sockets, receive and send back the data
            length = recv( ClientSock[i], bfr, sizeof(bfr), 0);

            res = STR_OK;
            res = RunServer(i, (BYTE*)bfr, sizeof(bfr), &length);
            if(res==STR_NEED_ANSWER) {
                send(ClientSock[i], bfr, length, 0);
                res = STR_OK;
            }

            if(( length < 0 )||(res != STR_OK))
            {
                closesocket( ClientSock[i] );
                ClientSock[i] = INVALID_SOCKET;
            }
            ClientsCnt++;
        }
        //if(ClientsCnt == 0) LED1_IO = 0;
        break;

    default:
        return;
    }
    return;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: ksergy1/interview
int main(int argc, char **argv)
{
    if (argc < 9) {
        std::cout << "usage: " << argv[0]
                  << " host port username password"
                  << " database-name table-name server-host server-port"
                  << std::endl;
        exit(0);
    }
    std::string _host = argv[1],
                _port = argv[2],
                _username = argv[3],
                _password = argv[4],
                _db_name = argv[5],
                _table_name = argv[6],
                _s_host = argv[7],
                _s_port = argv[8];
    try {
        bool res =
            Database::getInstance().Connect(
                                            _host,
                                            _port,
                                            _username,
                                            _password,
                                            _db_name,
                                            _table_name
                                        );
        if (!res) {
            std::cout << "Cannot connect to database:\n"
                      << "\thost - " << _host << "\n"
                      << "\tport - " << _port << "\n"
                      << "\tusername - " << _username << "\n"
                      << "\tpassword - " << _password << "\n"
                      << "\t_db_name - " << _db_name << "\n"
                      << "\t_table_name - " << _table_name << "\n";
            return 1;
        }

/************************************************************
        // Do sample requests (for test of DB class
        DBRequest _request;

        _request.request_type = REQUEST_GET;
        _request.any_request.get_request.id = 0;
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_GET;
        _request.any_request.get_request.id = 1000;
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_GET;
        _request.any_request.get_request.id = 1;
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_POST;
        _request.any_request.post_request.id = 0;
        _request.any_request.post_request.first_name = strdup("Sergey");
        _request.any_request.post_request.last_name = strdup("Kanaev");
        _request.any_request.post_request.birth_date = strdup("06-10-1991");
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_POST;
        _request.any_request.post_request.id = 1;
        _request.any_request.post_request.first_name = strdup("fnameChanged");
        _request.any_request.post_request.last_name = strdup("lNameChanged");
        _request.any_request.post_request.birth_date = strdup("08-10-1900");
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_DELETE;
        _request.any_request.delete_request.id = 10000;
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_POST;
        _request.any_request.post_request.id = 0;
        _request.any_request.post_request.first_name = NULL;
        _request.any_request.post_request.last_name = strdup("Kanaev");
        _request.any_request.post_request.birth_date = strdup("06-10-1991");
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());

        _request.request_type = REQUEST_DELETE;
        _request.any_request.delete_request.id = 1;
        Database::getInstance().QueueRequest(_request, async_server::connection_ptr());
************************************************************/

        RunServer(_s_host, _s_port);
        Database::getInstance().Disconnect();
    }
    catch (std::string e) {
        std::cout << "String catched: " <<
                     e << std::endl;
        return 1;
    }
    catch (pqxx::usage_error e) {
        std::cout << "PQXX says: " <<
                     e.what() << std::endl;
    }
    catch (const std::exception& e) {
        std::cout << "Abnormal termination: " <<
                     e.what() << std::endl;
        return 1;
    }

    //std::cout << "Waiting for thread pool to empty" << std::endl;
    std::cout << "Destroying thread pool object" << std::endl;
    //sleep(5);
    threadPool.reset();

    std::cout << "Terminated normally" << std::endl;
    return 0;
}