ScummVM API documentation
Networking::Host Class Reference

Public Member Functions

 Host (ENetHost *host)
 
 Host (ENetHost *host, ENetPeer *serverPeer)
 
uint8 service (int timeout=0)
 
bool connectPeer (const Common::String &address, int port, int timeout=5000, int numChannels=1)
 
void disconnectPeer (int peerIndex)
 
bool send (const char *data, int peerIndex, int channel=0, bool reliable=true)
 
bool sendRawData (const Common::String &address, int port, const char *data)
 
Common::String getHost ()
 
int getPort ()
 
int getPeerIndexFromHost (const Common::String &host, int port)
 
Common::String getPacketData ()
 
void destroyPacket ()
 

Constructor & Destructor Documentation

◆ Host() [1/2]

Networking::Host::Host ( ENetHost host)

A representation of ENetHost.

Parameters
hostA pointer to ENetHost given by the createHost function.
See also
Networking::ENet::createHost

◆ Host() [2/2]

Networking::Host::Host ( ENetHost host,
ENetPeer serverPeer 
)

A representation of ENetHost, connected to a server peer.

Parameters
hostA pointer to ENetHost given by the connnectToHost function.
serverPeera pointer to a connected peer given by the connnectToHost function.
See also
Networking::ENet::connectToHost

Member Function Documentation

◆ service()

uint8 Networking::Host::service ( int  timeout = 0)

Services the host which receives or sends pending messages, intended to be called at the start of a game loop.

Parameters
timeoutnumber of milliseconds that ENet should wait for events.
Return values
>0 if an event occurred within the specified time limit.
0if no event occurred.
<0 on failure.

◆ connectPeer()

bool Networking::Host::connectPeer ( const Common::String address,
int  port,
int  timeout = 5000,
int  numChannels = 1 
)

Connected to a foreign peer.

Parameters
addressthe address of the peer that will attempt to connect to.
portthe port number of the peer that will attempt to connect to.
timeoutspecifies the connection timeout in milliseconds, 5 full seconds by default. Will fail if the given time has passed.
numChannelsthe maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT. This must match with the connecting peer.
Return values
trueon successful.
falseon failure.

◆ disconnectPeer()

void Networking::Host::disconnectPeer ( int  peerIndex)

Disconnects a specific peer from the host.

Parameters
peerIndexIndex of a peer to disconnect.
Note
A peer index can be retrieved from the getPeerIndexFromHost function.

◆ send()

bool Networking::Host::send ( const char *  data,
int  peerIndex,
int  channel = 0,
bool  reliable = true 
)

Creates a packet and sends to a peer.

Parameters
dataContents of the packet's data; the packet's data will remain uninitialized if data is NULL.
peerIndexIndex of a peer to send the packet to.
channelchannel on which to send; 0 by default.
reliableIndicates that the packet must be received by the target peer and resend attempts will be made until the packet is delivered.
Return values
trueon successful.
falseon failure.
Note
Currently, if this object is created by the connectToHost function, data will always get sent to _serverPeer regardless of index given.

◆ sendRawData()

bool Networking::Host::sendRawData ( const Common::String address,
int  port,
const char *  data 
)

Sends raw data to an address outside the ENet protocol using its UDP socket directly.

Parameters
addressAddress to send data to.
portPort number to send data to.
dataThe data which will be sent.
Return values
trueon successful.
falseon failure.
Note
This sends data as a raw connection-less UDP socket, the same functionaility as a Networking::Socket object, but retains the address and port this host object is using.
Useful for hole-punching a peer, so it can connect to it.

◆ getHost()

Common::String Networking::Host::getHost ( )

Gets the host name of a peer that have recently connected, disconnected or received packet from.

Returns
String containing the host name.
Note
service() must be called and returned > 0 for this function to work.

◆ getPort()

int Networking::Host::getPort ( )

Gets the port number of a peer that have recently connected, disconnected or received packet from.

Returns
A port number.
Note
service() must be called and returned > 0 for this function to work.

◆ getPeerIndexFromHost()

int Networking::Host::getPeerIndexFromHost ( const Common::String host,
int  port 
)

Gets an index from a connected peer.

Parameters
hostA peer's host name
portA peer's port number.
Return values
>=0 containing a peer index if successfully found.
-1if not found.

◆ getPacketData()

Common::String Networking::Host::getPacketData ( )

Gets the data from the most-recently received packet.

Returns
String containing the packet's data.
Note
service() must be called and returned ENET_EVENT_TYPE_RECEIVE (3) for this function to work.

◆ destroyPacket()

void Networking::Host::destroyPacket ( )

Deallocate the packet, must be called upon receiving and finished using the packet's data.


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