mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
*** empty log message ***
This commit is contained in:
parent
2aad00356a
commit
df5c57b73c
@ -147,31 +147,8 @@ DirectD::~DirectD() {
|
|||||||
cerr<<"DirectD dtor"<<endl;
|
cerr<<"DirectD dtor"<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DirectDServer::DirectDServer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
DirectDServer::~DirectDServer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DirectDClient::DirectDClient() {
|
|
||||||
}
|
|
||||||
|
|
||||||
DirectDClient::~DirectDClient() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DirectDClient::handle_command(const string& cmd) {
|
|
||||||
if (_verbose) {
|
|
||||||
cerr<<"command: "<<cmd<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
DirectD::client_is_ready(const string& client_host, int port) {
|
DirectD::client_ready(const string& client_host, int port) {
|
||||||
connect_to(client_host, port);
|
connect_to(client_host, port);
|
||||||
send_command("s");
|
send_command("s");
|
||||||
disconnect_from(client_host, port);
|
disconnect_from(client_host, port);
|
||||||
@ -206,7 +183,8 @@ DirectD::wait_for_servers(int count, int timeout_ms) {
|
|||||||
//handle_datagram(datagram);
|
//handle_datagram(datagram);
|
||||||
DatagramIterator di(datagram);
|
DatagramIterator di(datagram);
|
||||||
string s=di.get_string();
|
string s=di.get_string();
|
||||||
if (s=="r" && --count) {
|
cerr<<"wait_for_servers() count="<<count<<", s="<<s<<endl;
|
||||||
|
if (s=="r" && !--count) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,38 +199,17 @@ DirectD::wait_for_servers(int count, int timeout_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
DirectD::server_is_ready(const string& client_host, int port) {
|
DirectD::server_ready(const string& client_host, int port) {
|
||||||
connect_to(client_host, port);
|
send_one_message(client_host, port, "r");
|
||||||
send_command("r");
|
|
||||||
disconnect_from(client_host, port);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::set_host_name(const string& host_name) {
|
|
||||||
_host_name=host_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::set_port(int port) {
|
|
||||||
_port=port;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::send_start_app(const string& cmd) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectD::start_app(const string& cmd) {
|
DirectD::start_app(const string& cmd) {
|
||||||
_app_pid=StartApp(cmd);
|
_app_pid=StartApp(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::send_kill_app(const string& cmd) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectD::kill_app() {
|
DirectD::kill_app() {
|
||||||
if (_app_pid) {
|
if (_app_pid) {
|
||||||
@ -272,29 +229,6 @@ DirectD::send_command(const string& cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::cli_command(const string& cmd) {
|
|
||||||
cerr<<"command "<<cmd<<endl;
|
|
||||||
if (cmd[0]=='!') {
|
|
||||||
// ...connect to host.
|
|
||||||
cerr<<"Local command "<<flush;
|
|
||||||
string code;
|
|
||||||
cin >> code;
|
|
||||||
string host;
|
|
||||||
cin >> host;
|
|
||||||
int port;
|
|
||||||
cin >> port;
|
|
||||||
cerr<<"connect ("<<code<<") to "<<host<<" port "<<port<<endl;
|
|
||||||
connect_to(host, port);
|
|
||||||
} else {
|
|
||||||
send_command(cmd);
|
|
||||||
if (cmd[0] == 'q' && cmd.size()==1) {
|
|
||||||
// ...user entered quit command.
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectD::handle_datagram(NetDatagram& datagram){
|
DirectD::handle_datagram(NetDatagram& datagram){
|
||||||
DatagramIterator di(datagram);
|
DatagramIterator di(datagram);
|
||||||
@ -307,47 +241,38 @@ DirectD::handle_command(const string& cmd) {
|
|||||||
if (_verbose) {
|
if (_verbose) {
|
||||||
cerr<<"command: "<<cmd<<endl;
|
cerr<<"command: "<<cmd<<endl;
|
||||||
}
|
}
|
||||||
if (cmd.size()==1) {
|
|
||||||
switch (cmd[0]) {
|
|
||||||
case 's': {
|
|
||||||
string c;
|
|
||||||
read_command(c);
|
|
||||||
start_app(c);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'k':
|
|
||||||
kill_app();
|
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
_shutdown=true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cerr<<"unknown command: "<<cmd<<endl;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
start_app(cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectD::read_command(string& cmd) {
|
DirectD::send_one_message(const string& host_name,
|
||||||
try {
|
int port,
|
||||||
ifstream f;
|
const string& message) {
|
||||||
f.open("directdCommand", ios::in | ios::binary);
|
NetAddress host;
|
||||||
stringstream ss;
|
if (!host.set_host(host_name, port)) {
|
||||||
const buf_size=512;
|
nout << "Unknown host: " << host_name << "\n";
|
||||||
char buf[buf_size];
|
|
||||||
f.getline(buf, buf_size);
|
|
||||||
if (f.gcount() > 0) {
|
|
||||||
cmd = buf;
|
|
||||||
cerr<<"read_command "<<cmd<<endl;
|
|
||||||
}
|
|
||||||
f.close();
|
|
||||||
} catch (...) {
|
|
||||||
// This could be bad, I suppose. But we're going to throw out
|
|
||||||
// any exceptions that happen during the above read.
|
|
||||||
cerr<<"DirectD::read_command() exception."<<endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int timeout_ms=5000;
|
||||||
|
PT(Connection) c = _cm.open_TCP_client_connection(host, timeout_ms);
|
||||||
|
if (c.is_null()) {
|
||||||
|
nout << "No connection.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nout << "Successfully opened TCP connection to " << host_name
|
||||||
|
<< " on port "
|
||||||
|
<< c->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
|
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);
|
PT(Connection) c = _cm.open_TCP_client_connection(host, timeout_ms);
|
||||||
if (c.is_null()) {
|
if (c.is_null()) {
|
||||||
nout << "No connection.\n";
|
nout << "No connection.\n";
|
||||||
exit(1);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nout << "Successfully opened TCP connection to " << host_name
|
nout << "Successfully opened TCP connection to " << host_name
|
||||||
@ -375,11 +300,13 @@ DirectD::connect_to(const string& host_name, int port) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
DirectD::disconnect_from(const string& host_name, int port) {
|
DirectD::disconnect_from(const string& host_name, int port) {
|
||||||
|
nout<<"disconnect_from(\""<<host_name<<", port="<<port<<")"<<endl;
|
||||||
for (ConnectionSet::iterator i=_connections.begin(); i != _connections.end(); ++i) {
|
for (ConnectionSet::iterator i=_connections.begin(); i != _connections.end(); ++i) {
|
||||||
if ((*i)->get_address().get_ip_string()==host_name
|
nout<<" found "<<(*i)->get_address().get_ip_string()<<", port "<<(*i)->get_address().get_port()<<endl;
|
||||||
&& (*i)->get_address().get_port()==port) {
|
if ((*i)->get_address().get_ip_string()==host_name) {
|
||||||
_cm.close_connection((*i));
|
nout<<" disconnecting."<<endl;
|
||||||
_reader.remove_connection((*i));
|
_reader.remove_connection((*i));
|
||||||
|
_cm.close_connection((*i));
|
||||||
_connections.erase(i);
|
_connections.erase(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -445,39 +372,3 @@ DirectD::check_for_new_clients() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::run_server() {
|
|
||||||
if (_verbose) cerr<<"server"<<endl;
|
|
||||||
|
|
||||||
listen_to(_port);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
check_for_new_clients();
|
|
||||||
check_for_lost_connection();
|
|
||||||
check_for_datagrams();
|
|
||||||
|
|
||||||
// Yield the timeslice before we poll again.
|
|
||||||
PR_Sleep(PR_MillisecondsToInterval(200));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DirectD::run_client() {
|
|
||||||
if (_verbose) {
|
|
||||||
cerr<<"client"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect_to(_host_name, _port);
|
|
||||||
|
|
||||||
while (!cin.fail() && _connections.size()!=0) {
|
|
||||||
cout << "directd send: " << flush;
|
|
||||||
string d;
|
|
||||||
cin >> d;
|
|
||||||
cli_command(d);
|
|
||||||
|
|
||||||
check_for_lost_connection();
|
|
||||||
check_for_datagrams();
|
|
||||||
}
|
|
||||||
nout << "Exiting\n";
|
|
||||||
}
|
|
||||||
|
@ -16,17 +16,6 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This is a work in progress, if you have any questions, ask skyler.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include "pandabase.h"
|
#include "pandabase.h"
|
||||||
@ -42,31 +31,21 @@ typedef int intptr_t;
|
|||||||
#endif //]
|
#endif //]
|
||||||
|
|
||||||
|
|
||||||
/*
|
// Description: DirectD is a client/server app for starting panda/direct.
|
||||||
DirectD is a client/server app for starting panda/direct.
|
//
|
||||||
|
// Usage:
|
||||||
Usage:
|
// Start a directd server on each of the machines you
|
||||||
DirectD is both the client and the server, what it does depends on
|
// which to start panda on.
|
||||||
which command line argumenta are given at startup.
|
//
|
||||||
|
// Start a directd client on the controlling machine or
|
||||||
Start a directd server on each of the machines you which to start
|
// import ShowBaseGlobal with the xxxxx flag in your
|
||||||
panda on.
|
// Configrc. The client will connact each of the servers
|
||||||
|
// in the xxxxx list in your Configrc.
|
||||||
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 {
|
class EXPCL_DIRECT DirectD {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
DirectD();
|
DirectD();
|
||||||
~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.
|
// Description: Call listen_to in the server.
|
||||||
// port is a rendezvous port.
|
// port is a rendezvous port.
|
||||||
//
|
//
|
||||||
@ -74,44 +53,40 @@ PUBLISHED:
|
|||||||
// before you handle them. Consider setting backlog to
|
// before you handle them. Consider setting backlog to
|
||||||
// the count you send to wait_for_servers(); or higher.
|
// the count you send to wait_for_servers(); or higher.
|
||||||
void listen_to(int port, int backlog=8);
|
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
|
// Description: Call this function from the client when
|
||||||
// import ShowbaseGlobal is nearly finished.
|
// 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
|
// Description: Call this function from the client after
|
||||||
// calling <count> client_is_ready() calls.
|
// calling <count> client_ready() calls.
|
||||||
//
|
//
|
||||||
// Call listen_to(port) prior to calling
|
// Call listen_to(port) prior to calling
|
||||||
// wait_for_servers() (or better yet, prior
|
// 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);
|
bool wait_for_servers(int count, int timeout_ms);
|
||||||
|
|
||||||
// Description: Call this function from the server when
|
// Description: Call this function from the server when
|
||||||
// import ShowbaseGlobal is nearly finished.
|
// 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:
|
public:
|
||||||
void set_host_name(const string& host_name);
|
|
||||||
void set_port(int port);
|
|
||||||
void spawn_background_server();
|
void spawn_background_server();
|
||||||
|
|
||||||
void run_server();
|
|
||||||
void run_client();
|
|
||||||
|
|
||||||
void send_start_app(const string& cmd);
|
|
||||||
void start_app(const string& cmd);
|
void start_app(const string& cmd);
|
||||||
|
|
||||||
void send_kill_app(const string& pid);
|
|
||||||
void kill_app();
|
void kill_app();
|
||||||
|
|
||||||
void cli_command(const string& cmd);
|
|
||||||
void handle_command(const string& cmd);
|
void handle_command(const string& cmd);
|
||||||
|
|
||||||
void handle_datagram(NetDatagram& datagram);
|
void handle_datagram(NetDatagram& datagram);
|
||||||
|
void send_one_message(const string& host_name,
|
||||||
|
int port, const string& message);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QueuedConnectionManager _cm;
|
QueuedConnectionManager _cm;
|
||||||
@ -131,21 +106,4 @@ protected:
|
|||||||
void check_for_new_clients();
|
void check_for_new_clients();
|
||||||
void check_for_datagrams();
|
void check_for_datagrams();
|
||||||
void check_for_lost_connection();
|
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
@ -14,6 +14,16 @@
|
|||||||
#define OTHER_LIBS $[OTHER_LIBS] pystub
|
#define OTHER_LIBS $[OTHER_LIBS] pystub
|
||||||
|
|
||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
directdServer.cxx
|
directdServer.cxx directdServer.h
|
||||||
|
|
||||||
#end bin_target
|
#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
|
||||||
|
92
direct/src/directdServer/directdClient.cxx
Normal file
92
direct/src/directdServer/directdClient.cxx
Normal file
@ -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 "<<cmd<<endl;
|
||||||
|
if (cmd[0]=='!') {
|
||||||
|
// ...connect to host.
|
||||||
|
cerr<<"Local command "<<flush;
|
||||||
|
string code;
|
||||||
|
cin >> code;
|
||||||
|
string host;
|
||||||
|
cin >> host;
|
||||||
|
int port;
|
||||||
|
cin >> port;
|
||||||
|
cerr<<"connect ("<<code<<") to "<<host<<" port "<<port<<endl;
|
||||||
|
connect_to(host, port);
|
||||||
|
} else {
|
||||||
|
send_command(cmd);
|
||||||
|
if (cmd[0] == 'q' && cmd.size()==1) {
|
||||||
|
// ...user entered quit command.
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DirectDClient::run_client(const string& host, int port) {
|
||||||
|
if (_verbose) {
|
||||||
|
cerr<<"client"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect_to(host, port);
|
||||||
|
|
||||||
|
while (!cin.fail() && _connections.size()!=0) {
|
||||||
|
cout << "directd send: " << flush;
|
||||||
|
string d;
|
||||||
|
cin >> 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 [[<host>] <port>]\n"
|
||||||
|
" host default localhost\n"
|
||||||
|
" port default 8001\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cerr<<"directdClient"<<endl;
|
||||||
|
string host="localhost";
|
||||||
|
int port=8001;
|
||||||
|
if (argc >= 3) {
|
||||||
|
host=argv[argc-2];
|
||||||
|
}
|
||||||
|
if (argc > 1) {
|
||||||
|
port=(atoi(argv[argc-1]));
|
||||||
|
}
|
||||||
|
DirectDClient directd;
|
||||||
|
directd.run_client(port);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
32
direct/src/directdServer/directdClient.h
Normal file
32
direct/src/directdServer/directdClient.h
Normal file
@ -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);
|
||||||
|
};
|
||||||
|
|
1
direct/src/directdServer/directdCommand
Normal file
1
direct/src/directdServer/directdCommand
Normal file
@ -0,0 +1 @@
|
|||||||
|
bash calc
|
@ -1,6 +1,5 @@
|
|||||||
// Filename: directd.cxx
|
// Filename: directdServer.cxx
|
||||||
// Created by: skyler 2002.04.08
|
// 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: "<<cmd<<endl;
|
||||||
|
}
|
||||||
|
if (cmd.size()==1) {
|
||||||
|
switch (cmd[0]) {
|
||||||
|
case 's': {
|
||||||
|
string c;
|
||||||
|
read_command(c);
|
||||||
|
start_app(c);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
kill_app();
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
_shutdown=true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cerr<<"unknown command: "<<cmd<<endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
start_app(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DirectDServer::read_command(string& cmd) {
|
||||||
|
try {
|
||||||
|
ifstream f;
|
||||||
|
f.open("directdCommand", ios::in | ios::binary);
|
||||||
|
stringstream ss;
|
||||||
|
const buf_size=512;
|
||||||
|
char buf[buf_size];
|
||||||
|
f.getline(buf, buf_size);
|
||||||
|
if (f.gcount() > 0) {
|
||||||
|
cmd = buf;
|
||||||
|
cerr<<"read_command "<<cmd<<endl;
|
||||||
|
}
|
||||||
|
f.close();
|
||||||
|
} catch (...) {
|
||||||
|
// This could be bad, I suppose. But we're going to throw out
|
||||||
|
// any exceptions that happen during the above read.
|
||||||
|
cerr<<"DirectD::read_command() exception."<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DirectDServer::run_server(int port) {
|
||||||
|
if (_verbose) cerr<<"server"<<endl;
|
||||||
|
|
||||||
|
listen_to(port);
|
||||||
|
|
||||||
|
while (!_shutdown) {
|
||||||
|
check_for_new_clients();
|
||||||
|
check_for_lost_connection();
|
||||||
|
check_for_datagrams();
|
||||||
|
|
||||||
|
// Yield the timeslice before we poll again.
|
||||||
|
PR_Sleep(PR_MillisecondsToInterval(200));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
if (argc > 1 && strcmp(argv[1], "--help")==0) {
|
if (argc > 1 && strcmp(argv[1], "--help")==0) {
|
||||||
cerr<<"directd [-c <host>] <port>\n"
|
cerr<<"directd [<port>]\n"
|
||||||
" -c run as client (else run as server).\n"
|
|
||||||
" host e.g. localhost\n"
|
|
||||||
" port default 8001\n";
|
" port default 8001\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr<<"directd"<<endl;
|
cerr<<"directdServer"<<endl;
|
||||||
DirectD directd;
|
int port=8001;
|
||||||
if (argc >= 3) {
|
|
||||||
string host=argv[argc-2];
|
|
||||||
directd.set_host_name(host);
|
|
||||||
}
|
|
||||||
char run_as=' ';
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
directd.set_port(atoi(argv[argc-1]));
|
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;
|
|
||||||
}
|
}
|
||||||
|
DirectDServer directd;
|
||||||
|
directd.run_server(port);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
40
direct/src/directdServer/directdServer.h
Normal file
40
direct/src/directdServer/directdServer.h
Normal file
@ -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);
|
||||||
|
};
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user