Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::RUdpConnection Class Reference

Network class that represents a reliable UDP connection. More...

Public Types

using SequenceIndex = UInt16
 

Public Member Functions

 RUdpConnection ()
 Constructs a RUdpConnection object by default.
 
 RUdpConnection (const RUdpConnection &)=delete
 
 RUdpConnection (RUdpConnection &&)=default
 
void Close ()
 Closes the connection.
 
bool Connect (const IpAddress &remoteAddress)
 Connects to the IpAddress. More...
 
bool Connect (const String &hostName, NetProtocol protocol=NetProtocol_Any, const String &service="http", ResolveError *error=nullptr)
 Connects to the hostname. More...
 
void Disconnect ()
 Disconnects the connection. More...
 
IpAddress GetBoundAddress () const
 Gets the bound address. More...
 
UInt16 GetBoundPort () const
 Gets the port of the bound address. More...
 
SocketError GetLastError () const
 Gets the last error. More...
 
bool Listen (NetProtocol protocol, UInt16 port=64266)
 Listens to a socket. More...
 
bool Listen (const IpAddress &address)
 Listens to a socket. More...
 
bool PollMessage (RUdpMessage *message)
 Polls the message. More...
 
bool Send (const IpAddress &clientIp, PacketPriority priority, PacketReliability reliability, const NetPacket &packet)
 Sends the packet to a peer. More...
 
void SetProtocolId (UInt32 protocolId)
 Sets the protocol id. More...
 
void SetTimeBeforeAck (UInt32 ms)
 Sets the time before ack. More...
 
void SimulateNetwork (double packetLoss)
 Simulates the loss of packets on network. More...
 
void Update ()
 Updates the reliable connection.
 
RUdpConnectionoperator= (const RUdpConnection &)=delete
 
RUdpConnectionoperator= (RUdpConnection &&)=default
 
 NazaraSignal (OnConnectedToPeer, RUdpConnection *)
 
 NazaraSignal (OnPeerAcknowledged, RUdpConnection *, const IpAddress &)
 
 NazaraSignal (OnPeerConnection, RUdpConnection *, const IpAddress &)
 
 NazaraSignal (OnPeerDisconnected, RUdpConnection *, const IpAddress &)
 

Static Public Attributes

static constexpr std::size_t MessageHeader = sizeof(UInt16) + 2 * sizeof(SequenceIndex) + sizeof(UInt32)
 
static constexpr std::size_t MessageFooter = sizeof(UInt16)
 

Friends

class Network
 

Detailed Description

Network class that represents a reliable UDP connection.

Member Function Documentation

◆ Connect() [1/2]

bool Nz::RUdpConnection::Connect ( const IpAddress remoteAddress)

Connects to the IpAddress.

Returns
true
Parameters
remoteAddressAddress to connect to
Remarks
Produces a NazaraAssert if socket is not bound
Produces a NazaraAssert if remote is invalid
Produces a NazaraAssert if port is not specified

◆ Connect() [2/2]

bool Nz::RUdpConnection::Connect ( const String hostName,
NetProtocol  protocol = NetProtocol_Any,
const String service = "http",
ResolveError *  error = nullptr 
)

Connects to the hostname.

Returns
true If successful
Parameters
hostNameHostname of the remote
protocolNet protocol to use
serviceSpecify the protocol used
errorOptional argument to get the error

◆ Disconnect()

void Nz::RUdpConnection::Disconnect ( )
inline

Disconnects the connection.

See also
Close

◆ GetBoundAddress()

IpAddress Nz::RUdpConnection::GetBoundAddress ( ) const
inline

Gets the bound address.

Returns
IpAddress we are linked to

◆ GetBoundPort()

UInt16 Nz::RUdpConnection::GetBoundPort ( ) const
inline

Gets the port of the bound address.

Returns
Port we are linked to

◆ GetLastError()

SocketError Nz::RUdpConnection::GetLastError ( ) const
inline

Gets the last error.

Returns
Socket error

◆ Listen() [1/2]

bool Nz::RUdpConnection::Listen ( NetProtocol  protocol,
UInt16  port = 64266 
)
inline

Listens to a socket.

Returns
true If successfully bound
Parameters
protocolNet protocol to listen to
portPort to listen to
Remarks
Produces a NazaraAssert if protocol is unknown or any

◆ Listen() [2/2]

bool Nz::RUdpConnection::Listen ( const IpAddress address)

Listens to a socket.

Returns
true If successfully bound
Parameters
remoteAddressAddress to listen to

◆ PollMessage()

bool Nz::RUdpConnection::PollMessage ( RUdpMessage *  message)

Polls the message.

Returns
true If there is a message
Parameters
messageMessage to poll
Remarks
Produces a NazaraAssert if message is invalid

◆ Send()

bool Nz::RUdpConnection::Send ( const IpAddress peerIp,
PacketPriority  priority,
PacketReliability  reliability,
const NetPacket packet 
)

Sends the packet to a peer.

Returns
true If peer exists (false may result from disconnected client)
Parameters
peerIpIpAddress of the peer
priorityPriority of the packet
reliabilityPolicy of reliability of the packet
packetPacket to send

Silently fail (probably a disconnected client)

◆ SetProtocolId()

void Nz::RUdpConnection::SetProtocolId ( UInt32  protocolId)
inline

Sets the protocol id.

Parameters
protocolIdProtocol ID like NNet

◆ SetTimeBeforeAck()

void Nz::RUdpConnection::SetTimeBeforeAck ( UInt32  ms)
inline

Sets the time before ack.

Parameters
Timebefore acking to send many together (in ms)

◆ SimulateNetwork()

void Nz::RUdpConnection::SimulateNetwork ( double  packetLoss)
inline

Simulates the loss of packets on network.

Parameters
packetLossRatio of packet loss according to bernoulli distribution
Remarks
Produces a NazaraAssert if packetLoss is not in between 0.0 and 1.0

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