![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A UDP socket. More...
#include <gf/UdpSocket.h>

Public Member Functions | |
| UdpSocket ()=default | |
| Default constructor. More... | |
| UdpSocket (AnyType, SocketFamily family=SocketFamily::Unspec) | |
| Full constructor. More... | |
| UdpSocket (const std::string &service, SocketFamily family=SocketFamily::Unspec) | |
| Full constructor. More... | |
| SocketAddress | getRemoteAddress (const std::string &hostname, const std::string &service) |
| Get a remote address for this socket. More... | |
| SocketDataResult | sendRawBytesTo (Span< const uint8_t > buffer, const SocketAddress &address) |
| Send some bytes over to the socket. More... | |
| SocketDataResult | recvRawBytesFrom (Span< uint8_t > buffer, SocketAddress &address) |
| Receive some bytes from the socket. More... | |
| bool | sendBytesTo (Span< const uint8_t > buffer, const SocketAddress &address) |
| Send a whole buffer to the socket. More... | |
| bool | recvBytesFrom (Span< uint8_t > buffer, SocketAddress &address) |
| Receive a whole buffer from the socket. More... | |
Public Member Functions inherited from gf::Socket | |
| ~Socket () | |
| Destructor. More... | |
| Socket (const Socket &)=delete | |
| Deleted copy constructor. More... | |
| Socket & | operator= (const Socket &)=delete |
| Deleted copy assignment. More... | |
| Socket (Socket &&other) noexcept | |
| Move constructor. More... | |
| Socket & | operator= (Socket &&other) noexcept |
| Move assignment. More... | |
| operator bool () const noexcept | |
| Boolean conversion. More... | |
| SocketAddress | getLocalAddress () const |
| Get the local address of the socket. More... | |
| void | setBlocking () |
| Set the socket in blocking mode. More... | |
| void | setNonBlocking () |
| Set the socket in non-blocking mode. More... | |
A UDP socket.
A UDP socket is a socket for UDP (User Datagram Protocol). UDP provides an unreliable communication between two hosts. UDP is connectionless i.e. no connection is established, the receiver must be set for each communication.
|
default |
Default constructor.
This constructor creates an invalid socket
| gf::UdpSocket::UdpSocket | ( | AnyType | , |
| SocketFamily | family = SocketFamily::Unspec |
||
| ) |
Full constructor.
It creates a UDP socket that is not bound to a specific port. The port is chosen by the system. It may be used by a client that do not need a specific port.
| family | The prefered socket family |
| gf::UdpSocket::UdpSocket | ( | const std::string & | service, |
| SocketFamily | family = SocketFamily::Unspec |
||
| ) |
Full constructor.
It creates a UDP socket that is bound on a specific port. It must be used in case a server wants to be joined with UDP on a specific port.
| service | The bound service |
| family | The prefered socket family |
| SocketAddress gf::UdpSocket::getRemoteAddress | ( | const std::string & | hostname, |
| const std::string & | service | ||
| ) |
Get a remote address for this socket.
This function provides a suitable socket address that can be used with the sending functions.
| hostname | The name of the host to communicate with |
| service | The service on the host to communicate with |
| bool gf::UdpSocket::recvBytesFrom | ( | Span< uint8_t > | buffer, |
| SocketAddress & | address | ||
| ) |
Receive a whole buffer from the socket.
This function ensures the buffer is received in a single packet.
| buffer | The buffer to store the received bytes |
| address | The address of the sending host |
| SocketDataResult gf::UdpSocket::recvRawBytesFrom | ( | Span< uint8_t > | buffer, |
| SocketAddress & | address | ||
| ) |
Receive some bytes from the socket.
| buffer | The buffer to store the received bytes |
| address | The address of the sending host |
| bool gf::UdpSocket::sendBytesTo | ( | Span< const uint8_t > | buffer, |
| const SocketAddress & | address | ||
| ) |
Send a whole buffer to the socket.
This function ensures the buffer is sent in a single packet.
| buffer | The buffer that contains the bytes to send |
| address | The address of the host to communicate with |
| SocketDataResult gf::UdpSocket::sendRawBytesTo | ( | Span< const uint8_t > | buffer, |
| const SocketAddress & | address | ||
| ) |
Send some bytes over to the socket.
| buffer | The buffer that contains the bytes to send |
| address | The address of the host to communicate with |