CUGL 2.5
Cornell University Game Library
|
#include <CUNetcodePeer.h>
Public Member Functions | |
NetcodePeer () | |
~NetcodePeer () | |
std::string | getUUID () const |
const std::shared_ptr< NetcodeChannel > | getChannel (const std::string channel) |
const std::shared_ptr< NetcodeConnection > | getConnection () |
bool | close () |
bool | send (const std::string channel, const std::vector< std::byte > &data) |
void | setDebug (bool flag) |
bool | getDebug () const |
Friends | |
class | NetcodeChannel |
class | NetcodeConnection |
This class represents a peer connection.
While NetcodeConnection
connects directly to the websocket server, peer connections are used to connect individual devices P2P (peer-to-peer). Each peer represents a connection between one device and another in the game. In turn, peers have one or more NetcodeChannel
objects to communicate between them.
Users should not create peer connections directly, and as such all constructors and allocators for this class are private. All peer connections are associated with a NetcodeConnection
and should be constructed from them. We have only exposed
this class to simplify development.
cugl::net::NetcodePeer::NetcodePeer | ( | ) |
Creates a degenerate RTC peer connection.
This object has not been initialized by a NetcodeConnection
and cannot be used.
You should NEVER USE THIS CONSTRUCTOR. Peer connections should be created by a NetcodeConnection
instead.
cugl::net::NetcodePeer::~NetcodePeer | ( | ) |
Deletes this RTC peer connection, disposing all resources
bool cugl::net::NetcodePeer::close | ( | ) |
Closes this peer connection.
All associated data channels will be destroyed. In addition, this connection will be removed from this parent.
const std::shared_ptr< NetcodeChannel > cugl::net::NetcodePeer::getChannel | ( | const std::string | channel | ) |
Returns the data channel with the associated label.
If there is no such channel, it returns nullptr. Most users should never need to access this method. It is provided for debugging purposes only.
This method is not const because it requires a lock.
const std::shared_ptr< NetcodeConnection > cugl::net::NetcodePeer::getConnection | ( | ) |
Returns the parent NetcodeConnection
of this data channel
Most users should never need to access this method. It is provided for debugging purposes only.
This method is not const because it requires a lock.
NetcodeConnection
of this data channel
|
inline |
Returns the debugging status of this peer.
If debugging is active, connections will be quite verbose
|
inline |
Returns the UUID of this peer
This value should correspond to NetcodeConnection#getUUID
of the connected peer.
bool cugl::net::NetcodePeer::send | ( | const std::string | channel, |
const std::vector< std::byte > & | data | ||
) |
Sends data along the data channel of the given name
Most users should never need to access this method. All communication should take place using the associated NetcodeConnection
. It is provided for debugging purposes only.
channel | The data channel label |
data | The data to send (a string or byte vector) |
void cugl::net::NetcodePeer::setDebug | ( | bool | flag | ) |
Toggles the debugging status of this peer.
If debugging is active, connections will be quite verbose
flag | Whether to activate debugging |
|
friend |
Allow access to the other netcode classes