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