00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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 }