DirectD is a client/server app for starting panda/direct. More...
#include "directd.h"
Public Member Functions | |
int | client_ready (const std::string &server_host, int port, const std::string &cmd) |
Call this function from the client when import ShowbaseGlobal is nearly finished. More... | |
int | connect_to (const std::string &server_host, int port) |
Call connect_to from client for each server. More... | |
void | disconnect_from (const std::string &server_host, int port) |
This is the counterpart to connect_to(). More... | |
void | listen_to (int port, int backlog=8) |
Call listen_to in the server. More... | |
void | send_command (const std::string &cmd) |
Send the same command string to all current connections. More... | |
int | server_ready (const std::string &client_host, int port) |
Call this function from the server when import ShowbaseGlobal is nearly finished. More... | |
int | tell_server (const std::string &server_host, int port, const std::string &cmd) |
Tell the server to do the command cmd. More... | |
bool | wait_for_servers (int count, int timeout_ms=2 *60 *1000) |
Call this function from the client after calling <count> client_ready() calls. More... | |
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 connect each of the servers in the xxxxx list in your Configrc.
There are two API groups in this class, they are:
listen_to() client_ready() or tell_server() wait_for_servers() server_ready()
and:
connect_to() send_command() disconnect_from()
The second group was from a more general implementation of DirectD. The first group summarizes the main intents of DirectD. Both groups are presented in order chronologically by their intended usage. The first group will probably provide everthing needed for DirectD.
int DirectD::client_ready | ( | const std::string & | server_host, |
int | port, | ||
const std::string & | cmd | ||
) |
Call this function from the client when import ShowbaseGlobal is nearly finished.
cmd: a cli command that will be executed on the remote machine. A new connection will be created and closed. If you want to send more than one command, you should use connect_to(), send_command(), and disconnect_from().
Definition at line 154 of file directd.cxx.
int DirectD::connect_to | ( | const std::string & | server_host, |
int | port | ||
) |
Call connect_to from client for each server.
returns the port number of the connection (which is different from the rendezvous port used in the second argument). The return value can be used for the port arguemnt in disconnect_from().
Definition at line 351 of file directd.cxx.
References NetAddress::set_host().
void DirectD::disconnect_from | ( | const std::string & | server_host, |
int | port | ||
) |
This is the counterpart to connect_to().
Pass the same server_host as for connect_to(), but pass the return value from connect_to() for the port, not the port passed to connect_to().
Definition at line 375 of file directd.cxx.
void DirectD::listen_to | ( | int | port, |
int | backlog = 8 |
||
) |
Call listen_to in the server.
port is a rendezvous port.
backlog refers to how many connections can queue up before you handle them. Consider setting backlog to the count you send to wait_for_servers(); or higher.
Definition at line 416 of file directd.cxx.
void DirectD::send_command | ( | const std::string & | cmd | ) |
Send the same command string to all current connections.
Definition at line 296 of file directd.cxx.
References Datagram::add_string(), and ConnectionWriter::send().
int DirectD::server_ready | ( | const std::string & | client_host, |
int | port | ||
) |
Call this function from the server when import ShowbaseGlobal is nearly finished.
Definition at line 210 of file directd.cxx.
int DirectD::tell_server | ( | const std::string & | server_host, |
int | port, | ||
const std::string & | cmd | ||
) |
Tell the server to do the command cmd.
cmd is one of the following: "k[<n>]" Kill the most recent application started with client_ready() or "!". Or kill the nth most recent or 'a' for All. E.g. "k", "k0", "k2", "ka". "q" Tell the server to quit. "!cmd" Exectue the cmd on the server (this is a dos shell command; if you want a bash command, include bash in the command e.g. "!bash pwd"). When you call client_ready(), it prefixes "!" for you. A new connection will be created and closed.
Definition at line 163 of file directd.cxx.
bool DirectD::wait_for_servers | ( | int | count, |
int | timeout_ms = 2*60*1000 |
||
) |
Call this function from the client after calling <count> client_ready() calls.
Call listen_to(port) prior to calling wait_for_servers() (or better yet, prior to calling client_ready()).
timeout_ms defaults to two minutes.
Definition at line 170 of file directd.cxx.
References QueuedConnectionReader::data_available(), Datagram::dump_hex(), NetDatagram::get_address(), and QueuedConnectionReader::get_data().