Class UDPSocketIPv6#
Defined in File UDPSocketIPv6.h
Inheritance Relationships#
Base Type#
public TRAP::Network::Socket
(Class Socket)
Class Documentation#
-
class UDPSocketIPv6 : public TRAP::Network::Socket#
Public Functions
-
constexpr UDPSocketIPv6()#
Constructor.
-
consteval UDPSocketIPv6(const UDPSocketIPv6&) = delete#
Copy constructor.
-
consteval UDPSocketIPv6 &operator=(const UDPSocketIPv6&) = delete#
Copy assignment operator.
-
constexpr UDPSocketIPv6(UDPSocketIPv6&&) noexcept = default#
Move constructor.
-
UDPSocketIPv6 &operator=(UDPSocketIPv6&&) noexcept = default#
Move assignment operator.
-
~UDPSocketIPv6() override = default#
Destructor.
-
u16 GetLocalPort() const#
Get the port to which the socket is bound locally.
If the socket is not bound to a port, this function returns 0.
- Returns:
Port to which the socket is bound.
-
Status Bind(u16 port, const IPv6Address &address = IPv6Address::Any)#
Bind the socket to a specific port.
Binding the socket to a port is necessary for being able to receive data on that port. When providing TRAP::Network::Socket::AnyPort as part, the listener will request an available port from the system. The chosen port can be retrieved by calling GetLocalPort().
Since the socket cn only be bound to a single port at any given moment, if it is already bound when this function is called, it will be unbound from the previous port before being bound to the new one.
- Parameters:
port – Port to bind the socket to.
address – Address of the interface to bind to.
- Returns:
Status code.
-
void Unbind()#
Unbind the socket from the local port to which it is bound.
The port that the socket was previously bound to is immediately made available to the operating system after this function is called. This means that a subsequent call to Bind() will be able to re-bind the port if no other process has done so in the mean time. If the socket is not bound to a port, this function has no effect.
-
Status Send(const void *data, usize size, const IPv6Address &remoteAddress, u16 remotePort)#
Send raw data to a remote peer.
Make sure that size is not greater than UDPSocket::MaxDatagramSize, otherwise this function will fail and no data will be sent.
- Parameters:
data – Pointer to the sequence of bytes to send.
size – Number of bytes to send.
remoteAddress – Address of the receiver.
remotePort – Port of the receiver to send the data to.
- Returns:
Status code.
-
Status Receive(void *data, usize size, usize &received, IPv6Address &remoteAddress, u16 &remotePort) const#
Receive raw data from a remote peer.
In blocking mode, this function will wait until some bytes are actually received. Be careful to use a buffer which is large enough for the data that you intend to receive, if it is too small then an error will be returned and all the data will be list.
- Parameters:
data – Pointer to the array to fill with the received bytes.
size – Maximum number of bytes that can be received.
received – This variable is filled with the actual number of bytes received.
remoteAddress – Address of the peer that sent the data.
remotePort – Port of the peer that sent the data.
- Returns:
Status code.
-
Status Send(Packet &packet, const IPv6Address &remoteAddress, u16 remotePort)#
Send a formatted packet of data to a remote peer.
Make sure that the packet size is not greater than UDPSocket::MaxDatagramSize, otherwise this function will fail and no data will be sent.
- Parameters:
packet – Packet to send.
remoteAddress – Address of the received.
remotePort – Port of the receiver to send the data to.
- Returns:
Status code.
-
Status Receive(Packet &packet, IPv6Address &remoteAddress, u16 &remotePort)#
Receive a formatted packet of data from a remote peer.
In blocking mode, this function will wait until the whole packet has been received.
- Parameters:
packet – Packet to fill with the received data.
remoteAddress – Address of the peer that sent the data.
remotePort – Port of the peer that sent the data.
- Returns:
Status code.
-
constexpr UDPSocketIPv6()#