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

Network class that represents a UDP socket, allowing for sending/receiving datagrams. More...

Inheritance diagram for Nz::UdpSocket:
Nz::AbstractSocket

Public Member Functions

 UdpSocket ()
 Constructs a UdpSocket object by default.
 
 UdpSocket (NetProtocol protocol)
 Constructs a UdpSocket object with a net protocol. More...
 
 UdpSocket (UdpSocket &&udpSocket)
 Constructs a UdpSocket object with another one by move semantic. More...
 
SocketState Bind (UInt16 port)
 Binds a specific port. More...
 
SocketState Bind (const IpAddress &address)
 Binds a specific IpAddress. More...
 
bool Create (NetProtocol protocol)
 Creates a UDP socket. More...
 
void EnableBroadcasting (bool broadcasting)
 Enables broadcasting. More...
 
IpAddress GetBoundAddress () const
 Gets the bound address. More...
 
UInt16 GetBoundPort () const
 Gets the port of the bound address. More...
 
bool IsBroadcastingEnabled () const
 Checks whether the broadcasting is enabled. More...
 
std::size_t QueryMaxDatagramSize ()
 Gets the maximum datagram size allowed. More...
 
bool Receive (void *buffer, std::size_t size, IpAddress *from, std::size_t *received)
 Receives the data available. More...
 
bool ReceiveMultiple (NetBuffer *buffers, std::size_t bufferCount, IpAddress *from, std::size_t *received)
 Receive multiple datagram from one peer. More...
 
bool ReceivePacket (NetPacket *packet, IpAddress *from)
 Receives the packet available. More...
 
bool Send (const IpAddress &to, const void *buffer, std::size_t size, std::size_t *sent)
 Sends the data available. More...
 
bool SendMultiple (const IpAddress &to, const NetBuffer *buffers, std::size_t bufferCount, std::size_t *sent)
 Sends multiple buffers as one datagram. More...
 
bool SendPacket (const IpAddress &to, const NetPacket &packet)
 Sends the packet available. More...
 
- Public Member Functions inherited from Nz::AbstractSocket
 AbstractSocket (const AbstractSocket &)=delete
 
 AbstractSocket (AbstractSocket &&abstractSocket)
 Constructs a AbstractSocket object with another one by move semantic. More...
 
virtual ~AbstractSocket ()
 Destructs the object and calls Close. More...
 
void Close ()
 Closes the socket.
 
void EnableBlocking (bool blocking)
 Enables blocking. More...
 
SocketError GetLastError () const
 Gets the last error. More...
 
SocketHandle GetNativeHandle () const
 Gets the internal socket handle. More...
 
SocketState GetState () const
 Gets the internal state. More...
 
SocketType GetType () const
 Gets the internal type. More...
 
bool IsBlockingEnabled () const
 Checks whether the blocking is enabled. More...
 
std::size_t QueryAvailableBytes () const
 Queries the available bytes. More...
 
std::size_t QueryReceiveBufferSize () const
 Queries the maximum socket receive buffer size. More...
 
std::size_t QuerySendBufferSize () const
 Queries the maximum socket send buffer size. More...
 
void SetReceiveBufferSize (std::size_t size)
 Sets the maximum receive buffer size. More...
 
void SetSendBufferSize (std::size_t size)
 Sets the maximum send buffer size. More...
 
AbstractSocketoperator= (const AbstractSocket &)=delete
 
AbstractSocketoperator= (AbstractSocket &&abstractSocket)
 Moves the AbstractSocket into this. More...
 
 NazaraSignal (OnStateChange, const AbstractSocket *, SocketState)
 

Additional Inherited Members

- Protected Member Functions inherited from Nz::AbstractSocket
 AbstractSocket (SocketType type)
 Constructs a AbstractSocket object with a type.
 
bool Open (NetProtocol protocol)
 Opens the socket according to a net protocol. More...
 
void Open (SocketHandle existingHandle)
 Opens the socket according to a socket handle. More...
 
void UpdateState (SocketState newState)
 Updates the state of the socket. More...
 
- Protected Attributes inherited from Nz::AbstractSocket
NetProtocol m_protocol
 
SocketError m_lastError
 
SocketHandle m_handle
 
SocketState m_state
 
SocketType m_type
 
bool m_isBlockingEnabled
 

Detailed Description

Network class that represents a UDP socket, allowing for sending/receiving datagrams.

Constructor & Destructor Documentation

◆ UdpSocket() [1/2]

Nz::UdpSocket::UdpSocket ( NetProtocol  protocol)
inline

Constructs a UdpSocket object with a net protocol.

Parameters
protocolNet protocol to use

◆ UdpSocket() [2/2]

Nz::UdpSocket::UdpSocket ( UdpSocket &&  udpSocket)
inline

Constructs a UdpSocket object with another one by move semantic.

Parameters
udpSocketUdpSocket to move into this

Member Function Documentation

◆ Bind() [1/2]

SocketState Nz::UdpSocket::Bind ( UInt16  port)
inline

Binds a specific port.

Returns
State of the socket
Parameters
portPort to bind

◆ Bind() [2/2]

SocketState Nz::UdpSocket::Bind ( const IpAddress address)

Binds a specific IpAddress.

Returns
State of the socket
Parameters
addressAddress to bind
Remarks
Produces a NazaraAssert if socket is invalid
Produces a NazaraAssert if address is invalid

◆ Create()

bool Nz::UdpSocket::Create ( NetProtocol  protocol)
inline

Creates a UDP socket.

Returns
true If successful
Parameters
protocolNet protocol to use

◆ EnableBroadcasting()

void Nz::UdpSocket::EnableBroadcasting ( bool  broadcasting)

Enables broadcasting.

Parameters
broadcastingShould the UDP broadcast
Remarks
Produces a NazaraAssert if socket is invalid

◆ GetBoundAddress()

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

Gets the bound address.

Returns
IpAddress we are linked to

◆ GetBoundPort()

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

Gets the port of the bound address.

Returns
Port we are linked to

◆ IsBroadcastingEnabled()

bool Nz::UdpSocket::IsBroadcastingEnabled ( ) const
inline

Checks whether the broadcasting is enabled.

Returns
true If it is the case

◆ QueryMaxDatagramSize()

std::size_t Nz::UdpSocket::QueryMaxDatagramSize ( )

Gets the maximum datagram size allowed.

Returns
Number of bytes
Remarks
Produces a NazaraAssert if socket is invalid

◆ Receive()

bool Nz::UdpSocket::Receive ( void *  buffer,
std::size_t  size,
IpAddress from,
std::size_t *  received 
)

Receives the data available.

Returns
true If data received
Parameters
bufferRaw memory to write
sizeSize of the buffer
fromIpAddress of the peer
receivedOptional argument to get the number of bytes received
Remarks
Produces a NazaraAssert if socket is invalid
Produces a NazaraAssert if buffer and its size is invalid

◆ ReceiveMultiple()

bool Nz::UdpSocket::ReceiveMultiple ( NetBuffer *  buffers,
std::size_t  bufferCount,
IpAddress from,
std::size_t *  received 
)

Receive multiple datagram from one peer.

Returns
true If data were sent
Parameters
toDestination IpAddress (must match socket protocol)
buffersA pointer to an array of NetBuffer containing buffers and size data
bufferCountNumber of buffers available
fromIpAddress of the peer
receivedOptional argument to get the number of bytes received

◆ ReceivePacket()

bool Nz::UdpSocket::ReceivePacket ( NetPacket packet,
IpAddress from 
)

Receives the packet available.

Returns
true If packet received
Parameters
packetPacket to receive
fromIpAddress of the peer
Remarks
Produces a NazaraAssert if packet is invalid
Produces a NazaraWarning if packet's header is invalid

◆ Send()

bool Nz::UdpSocket::Send ( const IpAddress to,
const void *  buffer,
std::size_t  size,
std::size_t *  sent 
)

Sends the data available.

Returns
true If data sended
Parameters
toIpAddress of the peer
bufferRaw memory to read
sizeSize of the buffer
sentOptional argument to get the number of bytes sent
Remarks
Produces a NazaraAssert if peer address is invalid
Produces a NazaraAssert if protocol of communication is not the same than the peer
Produces a NazaraAssert if buffer and its size is invalid

◆ SendMultiple()

bool Nz::UdpSocket::SendMultiple ( const IpAddress to,
const NetBuffer *  buffers,
std::size_t  bufferCount,
std::size_t *  sent 
)

Sends multiple buffers as one datagram.

Returns
true If data were sent
Parameters
toDestination IpAddress (must match socket protocol)
buffersA pointer to an array of NetBuffer containing buffers and size data
sizeNumber of NetBuffer to send
sentOptional argument to get the number of bytes sent

◆ SendPacket()

bool Nz::UdpSocket::SendPacket ( const IpAddress to,
const NetPacket packet 
)

Sends the packet available.

Returns
true If packet sent
Parameters
toIpAddress of the peer
packetPacket to send
Remarks
Produces a NazaraError if packet could not be prepared for sending

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