Panda3D
 All Classes Functions Variables Enumerations
directdClient.cxx
00001 // Filename: directdClient.cxx
00002 // Created by:  skyler 2002.04.08
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "directdClient.h"
00016 
00017 DirectDClient::DirectDClient() {
00018 }
00019 
00020 DirectDClient::~DirectDClient() {
00021 }
00022 
00023 void
00024 DirectDClient::cli_command(const string& cmd) {
00025   cerr<<"command "<<cmd<<endl;
00026   if (cmd[0]==':') {
00027     // ...connect to host.
00028     cerr<<"Local command "<<flush;
00029     string code;
00030     cin >> code;
00031     string host;
00032     cin >> host;
00033     int port;
00034     cin >> port;
00035     cerr<<"connect ("<<code<<") to "<<host<<" port "<<port<<endl;
00036     connect_to(host, port);
00037   } else {
00038     send_command(cmd);
00039     if (cmd[0] == 'q' && cmd.size()==1) {
00040       // ...user entered quit command.
00041       exit(0);
00042     }
00043   }
00044 }
00045 
00046 void
00047 DirectDClient::run_client(const string& host, int port) {
00048   nout<<"client"<<endl;
00049   
00050   connect_to(host, port);
00051 
00052   while (!cin.fail() && _connections.size()!=0) {
00053     cout << "directd send: " << flush;
00054     string d;
00055     cin >> d;
00056     cli_command(d);
00057 
00058     check_for_lost_connection();
00059     check_for_datagrams();
00060   }
00061   nout << "Exiting\n";
00062 }
00063 
00064 int
00065 main(int argc, char *argv[]) {
00066   if (argc > 1 && strcmp(argv[1], "--help")==0) {
00067     cerr<<"directd [[<host>] <port>]\n"
00068     "    host      default localhost\n"
00069     "    port      default 8001\n";
00070     return 1;
00071   }
00072 
00073   cerr<<"directdClient "<<__DATE__<<" "<<__TIME__<<endl;
00074   string host="localhost";
00075   int port=8001;
00076   if (argc >= 3) {
00077     host=argv[argc-2];
00078   }
00079   if (argc > 1) {
00080     port=(atoi(argv[argc-1]));
00081   }
00082   DirectDClient directd;
00083   directd.run_client(host, port);
00084   
00085   return 0;
00086 }
 All Classes Functions Variables Enumerations