Panda3D
 All Classes Functions Variables Enumerations
directdClient.cxx
1 // Filename: directdClient.cxx
2 // Created by: skyler 2002.04.08
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "directdClient.h"
16 
17 DirectDClient::DirectDClient() {
18 }
19 
20 DirectDClient::~DirectDClient() {
21 }
22 
23 void
24 DirectDClient::cli_command(const string& cmd) {
25  cerr<<"command "<<cmd<<endl;
26  if (cmd[0]==':') {
27  // ...connect to host.
28  cerr<<"Local command "<<flush;
29  string code;
30  cin >> code;
31  string host;
32  cin >> host;
33  int port;
34  cin >> port;
35  cerr<<"connect ("<<code<<") to "<<host<<" port "<<port<<endl;
36  connect_to(host, port);
37  } else {
38  send_command(cmd);
39  if (cmd[0] == 'q' && cmd.size()==1) {
40  // ...user entered quit command.
41  exit(0);
42  }
43  }
44 }
45 
46 void
47 DirectDClient::run_client(const string& host, int port) {
48  nout<<"client"<<endl;
49 
50  connect_to(host, port);
51 
52  while (!cin.fail() && _connections.size()!=0) {
53  cout << "directd send: " << flush;
54  string d;
55  cin >> d;
56  cli_command(d);
57 
58  check_for_lost_connection();
59  check_for_datagrams();
60  }
61  nout << "Exiting\n";
62 }
63 
64 int
65 main(int argc, char *argv[]) {
66  if (argc > 1 && strcmp(argv[1], "--help")==0) {
67  cerr<<"directd [[<host>] <port>]\n"
68  " host default localhost\n"
69  " port default 8001\n";
70  return 1;
71  }
72 
73  cerr<<"directdClient "<<__DATE__<<" "<<__TIME__<<endl;
74  string host="localhost";
75  int port=8001;
76  if (argc >= 3) {
77  host=argv[argc-2];
78  }
79  if (argc > 1) {
80  port=(atoi(argv[argc-1]));
81  }
82  DirectDClient directd;
83  directd.run_client(host, port);
84 
85  return 0;
86 }
DirectDClient is a test app for DriectDServer.
Definition: directdClient.h:18