示例#1
0
void MainWindow::setupMJ() {
    m_Server = new SwitchServer();

    /* Connect sendMessageToChatUi from m_Server to m_ChatWidget in order to display system messages
     * during the initialization. */
    connect(m_Server, SIGNAL(sendMessageToChatUi(QString)),
            ui->m_ChatWidget, SLOT(receivedMessage(QString))
    );

    // Server Initialization
    m_Server->init();

    // Initialize ChatWidget with the ChatServer
    ChatServer* chatServer = dynamic_cast<ChatServer*>(
                m_Server->getReceiver(TargetCode::CHAT_SERVER));
    ui->m_ChatWidget->setSenderServer(chatServer);

    // Initialize TokenMenu with the TokenMenuServer
    Receiver *tokenMenuServerReceiver = m_Server->getReceiver(TargetCode::TOKEN_MENU_SERVER);
    TokenMenuServer *tokenMenuServer = dynamic_cast<TokenMenuServer*>(tokenMenuServerReceiver);
    ui->tokenPage->setSenderServer(tokenMenuServer);

    // Initialize TurnMenu with the TurnMenuServer
    Receiver *turnMenuServerReceiver = m_Server->getReceiver(TargetCode::TURN_MENU_SERVER);
    TurnMenuClient *turnMenuServer = dynamic_cast<TurnMenuClient*>(turnMenuServerReceiver);
    ui->turnWidget->setSenderClient(turnMenuServer);

    setupPlayer();

    CmdNickname *cmdNickname = dynamic_cast<CmdNickname *>(
        chatServer->getCommands()->getUserCommand(ChatCodes::USERCMD_NICK)
    );
    connect(cmdNickname, SIGNAL(addPlayerToInterface(QString)),
            this, SLOT(addPlayerToInterface(QString)));
}
示例#2
0
文件: main.cpp 项目: sokie/networking
int main(int argc, char **argv) {
    std::string input;
    std::string rest;

    ChatServer* server = NULL;
    ChatClient* client = NULL;

    if (SDL_Init(0) == -1) {
        std::cerr << "SDL_Init: " << SDL_GetError() << std::endl;
        return 1;
    }
    if (SDLNet_Init() == -1) {
        std::cerr << "SDLNet_Init: " << SDLNet_GetError() << std::endl;
        return 1;
    }

    switch (argc) {
        case 2:
            server = new ChatServer((unsigned short)(atoi(argv[1])));
            while (true) {
                getline(std::cin, input);
                if (input == "quit") {
                    server->push(new LogoutRequest());
                    break;
                }
            }
            delete server;
            break;
        case 3:
            std::cout << "Username: "******"quit") {
                    client->push(new LogoutRequest());
                } else {
                    client->push(new MessageRequest(input));
                }
            }
            delete client;
            break;
        default:
            std::cout << "Usage:" << std::endl
                      << "\tdemo hostname port\t(start client)" << std::endl
                      << "\tdemo port\t\t(start server)" << std::endl;
    }

    SDLNet_Quit();
    SDL_Quit();
}
示例#3
0
int main(int argc, char **argv)
{
    std::cout << "Use " << argv[0] << " port_number to run on a specific port (default: "
              << DEFAULT_PORT << ".)\n\n";

    port pt(DEFAULT_PORT);

    if ( argc > 1 )
        pt = argv[1];

    ChatServer server;
    server.run(pt);
}
示例#4
0
文件: main.cpp 项目: edyp87/uwr_sr
int main(int argc, char *argv[]) {
	QApplication a(argc, argv);

    quint16 port = 5432;

    ChatServer server;
    server.listen(QHostAddress::Any, port);

    ChatClient client;
    client.show();

	return a.exec();
}
示例#5
0
int main(int argc, char *argv[])
{

	ChatServer server;
	if( server.connect() )
	{
		server.listeningLoop();
	}
	else
	{
		std::cerr << "Error: Could not start ChatServer.\n";
		return 1;
	}

	return 0; 
}
示例#6
0
int main(int argc, char* argv[])
{
    if (argc > 0)
    {
        argc--;
        argv++;
    }

    option::Stats stats(usage, argc, argv);
    option::Option options[stats.options_max];
    option::Option buffer[stats.buffer_max];

    option::Parser parse(usage, argc, argv, options, buffer);
    if (parse.error())
    {
        fprintf(stderr, "Error while parsing options\n");
        return 1;
    }

    if (options[HELP] || argc == 0)
    {
        option::printUsage(fwrite, stderr, usage, 80);
    }

    if (!options[PORT])
    {
        fprintf(stderr, "port missing");
        return 1;
    }

    signal(SIGTERM, term);
    signal(SIGINT, term);

    ChatServer* server = ChatServer::GetInstance();
    int err = server->Init(std::stoi(options[PORT].arg));

    if (err != 0)
    {
        std::cout << "Error listening" << uv_strerror(err) << std::endl;
    }
    else
    {
    }

    std::cout << "Server application exits" << std::endl;
    return 0;
}
示例#7
0
 void execute(XmlRpcValue& params, XmlRpcValue& result) 
 { 
      string tmp = params[0];
     vector<string> list = chat.Listar();
     for(int i = 0; i < list.size(); i++)
            result[i] = (string)list[i];
      
     cout << "Listando: " << result.size() <<  endl;
 } 
示例#8
0
 void execute(XmlRpcValue& params, XmlRpcValue& result) 
 { 
     result = "OK!";
             
     string login = (string)params[0];
     
     chat.Registrar(login);
    
     cout << "Registrando: " << login << "." << endl;
 } 
示例#9
0
 void execute(XmlRpcValue& params, XmlRpcValue& result) 
 { 
     result = "OK!"; 
     
     string login = params[0];
     
     chat.Sair(login);        
     
     cout << "Desregistrando: " << login <<  endl;
 } 
示例#10
0
pl_module_end


//[-------------------------------------------------------]
//[ Global functions                                      ]
//[-------------------------------------------------------]
/**
*  @brief
*    Run server
*/
int RunServer()
{
	// Create server at port '4000' with a maximum allowed number of '16' connections
	ChatServer cServer;
	cServer.SetMaxConnections(16);
	cServer.Listen(4000);

	// Main loop
	System::GetInstance()->GetConsole().Print("Press 'ESC' to exit the server\n");
	while (cServer.IsListening()) {
		// Let the system some time to process other system tasks etc.
		// If this isn't done the CPU usage is nearly up to 100%!
		System::GetInstance()->Sleep(1);

		// Check keys
		if (System::GetInstance()->GetConsole().IsKeyHit()) {
			// ESC: Exit server
			if (System::GetInstance()->GetConsole().GetCharacter() == 27) {
				// Shut down server
				cServer.Close();
			}
		}
	}

	// Done
	return 0;
}
示例#11
0
 void execute(XmlRpcValue& params, XmlRpcValue& result) 
 { 
               
     result = "OK!"; 
     
     string usr = params[0];
     string dest = params[1];
     string msg = params[2];
     
     chat.Enviar(usr,dest,msg);
     
     result = "OK";
     
     cout << "Enviando: " << params[0] << " -> " << params[1] <<  endl;
 } 
示例#12
0
 void execute(XmlRpcValue& params, XmlRpcValue& result) 
 { 
     result = "OK!";
             
     string login = (string)params[0];
     
     mensagem msg = chat.Receber(login);
     
     string rem = msg.remetente;
     string cor = msg.corpo;
     
     XmlRpcValue ret;
     
     ret[0] = rem;
     ret[1] = cor;
     
     result = ret;
     
     cout << "Receber: " <<  endl;
 } 
示例#13
0
int main( int argc, char **argv )
{
    ChatServer cs = ChatServer( 8080 );
    cs.run( );
}
示例#14
0
int
main(int argc, char* argv[])
{
    ChatServer app;
    return app.main(argc, argv);
}
示例#15
0
int
main(int argc, char* argv[])
{
    ChatServer app;
    return app.main(argc, argv, "config.server");
}
//////////////////////////////
/// DRIVER
//////////////////////////////
void driver(int argc, char * argv[]) {
  
  // Argument #2 is the first command line argument, so
  // we want to make sure we have some here.
  if (argc > 1) {
  
    string type(argv[1]);
    
    // Make the string lowercase so it's not case-sensitive.
    type = str_tolower(type);
    
    unsigned int port = DEFAULT_PORT;
    
    // If they supplied a port to use.
    if (argc > 2) {
    
      string port_str(argv[2]);
      port_str = str_tolower(port_str);
      
      if (port_str != "-d") {
      
        port = str_to_int(argv[2]);
      
      }
    
    }
    
    // Create an object of the requested type and start running.
    if (type == "s" || type == "server") {
    
      ChatServer server;
      server.setup(port);
      server.run();
    
    } else if (type == "c" || type == "client") {
    
      string hostname = DEFAULT_HOST;
      
      if (argc > 3) {
      
        hostname = argv[3];
      
      }
      
      ChatClient client;
      client.setup(port, hostname);
      client.run();
    
    } else {
    
      cout << "Invalid arguments provided." << endl;
      cout << "Please supply arguments to the program in this format:" << endl;
      cout << argv[0] << " type [port [hostname]]" << endl;
      cout << "type:     Either 'S' for server or 'C' for client." << endl;
      cout << "port:     The port number to use ('-d' for default)." << endl;
      cout << "          Note: this program defaults to port " << DEFAULT_PORT
           << "." << endl;
      cout << "hostname: The hostname or IP address of the server to" << endl;
      cout << "          connect to (only used as client)." << endl;
      cout << "These are case-insensitive." << endl;
    
    }
  
  } else {
  
    cout << "No arguments provided." << endl;
    cout << "Please supply arguments to the program in this format:" << endl;
    cout << argv[0] << " type [port [hostname]]" << endl;
    cout << "type:     Either 'S' for server or 'C' for client." << endl;
    cout << "port:     The port number to use ('-d' for default)." << endl;
    cout << "          Note: this program defaults to port " << DEFAULT_PORT
         << endl;
    cout << "hostname: The hostname or IP address of the server to" << endl;
    cout << "          connect to (only used as client)." << endl;
    cout << "These are case-insensitive." << endl;
  
  }
  
}