TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Classes | Public Member Functions | List of all members
torchcraft::Client Class Reference

#include <client.h>

Classes

struct  Command
 
struct  Options
 

Public Member Functions

 Client ()
 
 ~Client ()
 
 Client (const Client &)=delete
 
Clientoperator= (const Client &)=delete
 
bool connect (const std::string &hostname, int port, int timeoutMs)
 Create a socket connection and connect it to an endpoint specified by a TCP address parametrized by a hostname and a port. More...
 
bool connect (const std::string &file_socket, int timeoutMs)
 Creates a new socket and connects it to an endpoint by a file socket. More...
 
bool connected () const
 Indicates whether the connection was successfully established. More...
 
bool close ()
 Close the socket connection if it was previously successfully established and destroy the associated socket. More...
 
bool init (std::vector< std::string > &updates, const Options &opts=Options())
 Perform handshake over the established connection. More...
 
bool send (const std::vector< Command > &commands)
 Send a message containing commands over the established socket connection. More...
 
bool receive (std::vector< std::string > &updates)
 Receive a message containing state updates over the established socket connection. More...
 
bool poll (long timeout=-1)
 Blocks until a message is available for receive(). More...
 
std::string error () const
 
std::vector< CommandlastCommands () const
 
std::vector< int8_t > lastCommandsStatus () const
 
Statestate () const
 

Constructor & Destructor Documentation

torchcraft::Client::Client ( )
torchcraft::Client::~Client ( )
torchcraft::Client::Client ( const Client )
delete

Member Function Documentation

bool torchcraft::Client::close ( )

Close the socket connection if it was previously successfully established and destroy the associated socket.

Returns
true if the connection was closed successfully; false if the connection did not exist
bool torchcraft::Client::connect ( const std::string &  hostname,
int  port,
int  timeoutMs 
)

Create a socket connection and connect it to an endpoint specified by a TCP address parametrized by a hostname and a port.

The final endpoint is defined as tcp://<hostname>:<port>

Parameters
hostname[in] Hostname part of a TCP address for socket connection
port[in] Port part of a TCP address for socket connection
timeoutMs[in] Send / receive operation timeout in milliseconds, the value is interpreted as follows: -1 = blocking operation 0 = non-blocking operation without retries >0 = time (in milliseconds) after which the function returns an error, if the operation was not accomplished
Returns
true if the connection was established; false otherwise
bool torchcraft::Client::connect ( const std::string &  file_socket,
int  timeoutMs 
)

Creates a new socket and connects it to an endpoint by a file socket.

ZMQ IPC is used for the connection; the full address is thus ipc://<file_socket>

Parameters
file_socket[in] file to use as the socket
timeoutMs[in] Send / receive operation timeout in milliseconds (default = -1), the value is interpreted as follows: -1 = blocking operation 0 = non-blocking operation without retries >0 = time (in milliseconds) after which the function returns an error, if the operation was not accomplished
bool torchcraft::Client::connected ( ) const
inline

Indicates whether the connection was successfully established.

Returns
true if the connection was successfully established; false otherwise
std::string torchcraft::Client::error ( ) const
inline
bool torchcraft::Client::init ( std::vector< std::string > &  updates,
const Options opts = Options() 
)

Perform handshake over the established connection.

Parameters
updates[out] State field names that were updated from the handshake response
opts[in] Options to pass in the handshake message (default = Options())
Returns
true if the handshake succeeded; false otherwise
std::vector<Command> torchcraft::Client::lastCommands ( ) const
inline
std::vector<int8_t> torchcraft::Client::lastCommandsStatus ( ) const
inline
Client& torchcraft::Client::operator= ( const Client )
delete
bool torchcraft::Client::poll ( long  timeout = -1)

Blocks until a message is available for receive().

Returns
false on failure (timeout or lost connectivity), true otherwise
bool torchcraft::Client::receive ( std::vector< std::string > &  updates)

Receive a message containing state updates over the established socket connection.

Parameters
updates[out] State field names that were updated from the received message
Returns
true if the receive operation succeeded, false otherwise
bool torchcraft::Client::send ( const std::vector< Command > &  commands)

Send a message containing commands over the established socket connection.

Parameters
commands[in] Commands to send over the socket connection
Returns
true if the send operation succeeded, false otherwise
State* torchcraft::Client::state ( ) const
inline

The documentation for this class was generated from the following file: