Пример #1
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);
}
Пример #2
0
int main( int argc, char **argv )
{
    ChatServer cs = ChatServer( 8080 );
    cs.run( );
}
Пример #3
0
//////////////////////////////
/// 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;
  
  }
  
}