Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

direct/src/directdServer/directdClient.cxx

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

Generated on Fri May 2 01:37:21 2003 for Direct by doxygen1.3