From df5c57b73c1a38f8745ab32149ac6f9dbfd73c87 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Tue, 16 Apr 2002 01:02:57 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/directd/directd.cxx | 187 +++++---------------- direct/src/directd/directd.h | 92 +++------- direct/src/directdServer/Sources.pp | 12 +- direct/src/directdServer/directdClient.cxx | 92 ++++++++++ direct/src/directdServer/directdClient.h | 32 ++++ direct/src/directdServer/directdCommand | 1 + direct/src/directdServer/directdServer.cxx | 104 +++++++++--- direct/src/directdServer/directdServer.h | 40 +++++ 8 files changed, 318 insertions(+), 242 deletions(-) create mode 100644 direct/src/directdServer/directdClient.cxx create mode 100644 direct/src/directdServer/directdClient.h create mode 100644 direct/src/directdServer/directdCommand create mode 100644 direct/src/directdServer/directdServer.h diff --git a/direct/src/directd/directd.cxx b/direct/src/directd/directd.cxx index ddf70cf052..ece25db99f 100644 --- a/direct/src/directd/directd.cxx +++ b/direct/src/directd/directd.cxx @@ -147,31 +147,8 @@ DirectD::~DirectD() { cerr<<"DirectD dtor"<> code; - string host; - cin >> host; - int port; - cin >> port; - cerr<<"connect ("< 0) { - cmd = buf; - cerr<<"read_command "<get_address().get_port() << " and IP " + << c->get_address() << "\n"; + + //_reader.add_connection(c); + + NetDatagram datagram; + datagram.add_string(message); + _writer.send(datagram, c); + + //PR_Sleep(PR_MillisecondsToInterval(200)); + //_reader.remove_connection(c); + _cm.close_connection(c); } void @@ -361,7 +286,7 @@ DirectD::connect_to(const string& host_name, int port) { PT(Connection) c = _cm.open_TCP_client_connection(host, timeout_ms); if (c.is_null()) { nout << "No connection.\n"; - exit(1); + return; } nout << "Successfully opened TCP connection to " << host_name @@ -375,11 +300,13 @@ DirectD::connect_to(const string& host_name, int port) { void DirectD::disconnect_from(const string& host_name, int port) { + nout<<"disconnect_from(\""<get_address().get_ip_string()==host_name - && (*i)->get_address().get_port()==port) { - _cm.close_connection((*i)); + nout<<" found "<<(*i)->get_address().get_ip_string()<<", port "<<(*i)->get_address().get_port()<get_address().get_ip_string()==host_name) { + nout<<" disconnecting."<> d; - cli_command(d); - - check_for_lost_connection(); - check_for_datagrams(); - } - nout << "Exiting\n"; -} diff --git a/direct/src/directd/directd.h b/direct/src/directd/directd.h index 5962fa2528..2684d5e812 100644 --- a/direct/src/directd/directd.h +++ b/direct/src/directd/directd.h @@ -16,17 +16,6 @@ // //////////////////////////////////////////////////////////////////// - - - - -// This is a work in progress, if you have any questions, ask skyler. - - - - - - #include #include #include "pandabase.h" @@ -42,31 +31,21 @@ typedef int intptr_t; #endif //] -/* - DirectD is a client/server app for starting panda/direct. - - Usage: - DirectD is both the client and the server, what it does depends on - which command line argumenta are given at startup. - - Start a directd server on each of the machines you which to start - panda on. - - Start a directd client on the controlling machine or import - ShowBaseGlobal with the xxxxx flag in your Configrc. The client - will connact each of the servers in the xxxxx list in your Configrc. -*/ +// Description: DirectD is a client/server app for starting panda/direct. +// +// Usage: +// Start a directd server on each of the machines you +// which to start panda on. +// +// Start a directd client on the controlling machine or +// import ShowBaseGlobal with the xxxxx flag in your +// Configrc. The client will connact each of the servers +// in the xxxxx list in your Configrc. class EXPCL_DIRECT DirectD { PUBLISHED: DirectD(); ~DirectD(); - // Description: Call connect_to from client for each server. - void connect_to(const string& server_host, int port); - - // Description: - void disconnect_from(const string& server_host, int port); - // Description: Call listen_to in the server. // port is a rendezvous port. // @@ -74,44 +53,40 @@ PUBLISHED: // before you handle them. Consider setting backlog to // the count you send to wait_for_servers(); or higher. void listen_to(int port, int backlog=8); - - // Description: process command string. - void send_command(const string& cmd); // Description: Call this function from the client when // import ShowbaseGlobal is nearly finished. - int client_is_ready(const string& client_host, int port); + int client_ready(const string& client_host, int port); // Description: Call this function from the client after - // calling client_is_ready() calls. + // calling client_ready() calls. // // Call listen_to(port) prior to calling // wait_for_servers() (or better yet, prior - // to calling client_is_ready()). + // to calling client_ready()). bool wait_for_servers(int count, int timeout_ms); // Description: Call this function from the server when // import ShowbaseGlobal is nearly finished. - int server_is_ready(const string& client_host, int port); + int server_ready(const string& client_host, int port); + + // Description: Call connect_to from client for each server. + void connect_to(const string& server_host, int port); + + // Description: + void disconnect_from(const string& server_host, int port); + + // Description: process command string. + void send_command(const string& cmd); public: - void set_host_name(const string& host_name); - void set_port(int port); void spawn_background_server(); - - void run_server(); - void run_client(); - - void send_start_app(const string& cmd); void start_app(const string& cmd); - - void send_kill_app(const string& pid); void kill_app(); - - void cli_command(const string& cmd); void handle_command(const string& cmd); - void handle_datagram(NetDatagram& datagram); + void send_one_message(const string& host_name, + int port, const string& message); protected: QueuedConnectionManager _cm; @@ -131,21 +106,4 @@ protected: void check_for_new_clients(); void check_for_datagrams(); void check_for_lost_connection(); - - void read_command(string& cmd); }; - -class EXPCL_DIRECT DirectDServer: public DirectD { -public: - DirectDServer(); - ~DirectDServer(); -}; - -class EXPCL_DIRECT DirectDClient: public DirectD { -public: - DirectDClient(); - ~DirectDClient(); - - void handle_command(const string& cmd); -}; - diff --git a/direct/src/directdServer/Sources.pp b/direct/src/directdServer/Sources.pp index 7ad4c03db4..f688b0085e 100644 --- a/direct/src/directdServer/Sources.pp +++ b/direct/src/directdServer/Sources.pp @@ -14,6 +14,16 @@ #define OTHER_LIBS $[OTHER_LIBS] pystub #define SOURCES \ - directdServer.cxx + directdServer.cxx directdServer.h #end bin_target + +#begin test_bin_target + #define TARGET directdClient + #define LOCAL_LIBS directd + #define OTHER_LIBS $[OTHER_LIBS] pystub + + #define SOURCES \ + directdClient.cxx directdClient.h + +#end test_bin_target diff --git a/direct/src/directdServer/directdClient.cxx b/direct/src/directdServer/directdClient.cxx new file mode 100644 index 0000000000..4e076cdec8 --- /dev/null +++ b/direct/src/directdServer/directdClient.cxx @@ -0,0 +1,92 @@ +// Filename: directdClient.cxx +// Created by: skyler 2002.04.08 +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "directdClient.h" + +DirectDClient::DirectDClient() { +} + +DirectDClient::~DirectDClient() { +} + +void +DirectDClient::cli_command(const string& cmd) { + cerr<<"command "<> code; + string host; + cin >> host; + int port; + cin >> port; + cerr<<"connect ("<> d; + cli_command(d); + + check_for_lost_connection(); + check_for_datagrams(); + } + nout << "Exiting\n"; +} + +int +main(int argc, char *argv[]) { + if (argc > 1 && strcmp(argv[1], "--help")==0) { + cerr<<"directd [[] ]\n" + " host default localhost\n" + " port default 8001\n"; + return 1; + } + + cerr<<"directdClient"<= 3) { + host=argv[argc-2]; + } + if (argc > 1) { + port=(atoi(argv[argc-1])); + } + DirectDClient directd; + directd.run_client(port); + + return 0; +} diff --git a/direct/src/directdServer/directdClient.h b/direct/src/directdServer/directdClient.h new file mode 100644 index 0000000000..c3011a6ca6 --- /dev/null +++ b/direct/src/directdServer/directdClient.h @@ -0,0 +1,32 @@ +// Filename: directdClient.h +// Created by: skyler 2002.04.08 +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "directd.h" + +// Description: DirectDClient is a test app for DriectDServer. +class EXPCL_DIRECT DirectDClient: public DirectD { +public: + DirectDClient(); + ~DirectDClient(); + + void run_client(const string& host, int port); + +protected: + void cli_command(const string& cmd); +}; + diff --git a/direct/src/directdServer/directdCommand b/direct/src/directdServer/directdCommand new file mode 100644 index 0000000000..efafba4765 --- /dev/null +++ b/direct/src/directdServer/directdCommand @@ -0,0 +1 @@ +bash calc \ No newline at end of file diff --git a/direct/src/directdServer/directdServer.cxx b/direct/src/directdServer/directdServer.cxx index d0a565ba40..8db79fd676 100644 --- a/direct/src/directdServer/directdServer.cxx +++ b/direct/src/directdServer/directdServer.cxx @@ -1,6 +1,5 @@ -// Filename: directd.cxx +// Filename: directdServer.cxx // Created by: skyler 2002.04.08 -// Based on test_tcp_*.* by drose. // //////////////////////////////////////////////////////////////////// // @@ -17,40 +16,93 @@ // //////////////////////////////////////////////////////////////////// -#include "directd.h" +#include "directdServer.h" + +DirectDServer::DirectDServer() { +} + +DirectDServer::~DirectDServer() { +} + +void +DirectDServer::handle_command(const string& cmd) { + if (_verbose) { + cerr<<"command: "< 0) { + cmd = buf; + cerr<<"read_command "< 1 && strcmp(argv[1], "--help")==0) { - cerr<<"directd [-c ] \n" - " -c run as client (else run as server).\n" - " host e.g. localhost\n" + cerr<<"directd []\n" " port default 8001\n"; return 1; } - cerr<<"directd"<= 3) { - string host=argv[argc-2]; - directd.set_host_name(host); - } - char run_as=' '; + cerr<<"directdServer"< 1) { - directd.set_port(atoi(argv[argc-1])); - if (strlen(argv[1]) > 1 && argv[1][0] == '-') { - run_as=argv[1][1]; - } - } - switch (run_as) { - case 's': - directd.run_server(); - break; - case 'c': - default: - directd.run_client(); - break; + port=(atoi(argv[argc-1])); } + DirectDServer directd; + directd.run_server(port); return 0; } diff --git a/direct/src/directdServer/directdServer.h b/direct/src/directdServer/directdServer.h new file mode 100644 index 0000000000..fc71bf8af2 --- /dev/null +++ b/direct/src/directdServer/directdServer.h @@ -0,0 +1,40 @@ +// Filename: directdServer.h +// Created by: skyler 2002.04.08 +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "queuedConnectionReader.h" +#include "directd.h" + +// Description: Start a directdServer on each of the machines you +// which to start panda on. +// +// Start a directdClient on the controlling machine +// or import ShowBaseGlobal with the xxxxx flag in +// your Configrc. The client will connact each of +// the servers in the xxxxx list in your Configrc. +class DirectDServer: public DirectD { +public: + DirectDServer(); + ~DirectDServer(); + + void run_server(int port); + +protected: + void read_command(string& cmd); + void handle_command(const string& cmd); +}; +