![]() |
FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
|
A wrapper for UDP sockets inheriting from Socket. More...
#include <C_socket.hpp>
Public Types | |
enum | Type { TYPE_UDP , TYPE_TCP , TYPE_LISTENER_TCP } |
The possible types of sockets. More... | |
enum | Error { ERR_NOERROR = 0 , ERR_SUCCESS = ERR_NOERROR , ERR_DONE = ERR_NOERROR , ERR_PARTIAL , ERR_NOTREADY , ERR_DISCONNECTED , ERR_REFUSED , ERR_ALREADYCONNECTED , ERR_ALREADYUSED , ERR_TOOMANYSOCKET , ERR_NOTINIT , ERR_INVALIDARGUMENT , ERR_UNSUCCESS , ERR_UNKNOWN = ERR_UNSUCCESS } |
The error codes. More... | |
using | SocketDescriptor = int |
Public Member Functions | |
SocketUdp (IpAddress::Types addressType=IpAddress::Types::Ipv4) | |
SocketUdp (IpAddress::Types addressType, bool blocking, bool broadcast) | |
fge::net::Socket::Error | create () override |
Create a new socket. | |
fge::net::Socket::Error | connect (fge::net::IpAddress const &remoteAddress, fge::net::Port remotePort) |
Connect the socket to a remote address and port. | |
fge::net::Socket::Error | bind (fge::net::Port port, IpAddress const &address) |
Bind the socket to a local address and port. | |
fge::net::Socket::Error | send (void const *data, std::size_t size) |
Send data to the connected remote address. | |
fge::net::Socket::Error | sendTo (void const *data, std::size_t size, IpAddress const &remoteAddress, fge::net::Port remotePort) |
Send data to the specified address. | |
fge::net::Socket::Error | receiveFrom (void *data, std::size_t size, std::size_t &received, fge::net::IpAddress &remoteAddress, fge::net::Port &remotePort) |
Receive data from an unspecified remote address. | |
fge::net::Socket::Error | receive (void *data, std::size_t size, std::size_t &received) |
Receive data from the connected remote address. | |
fge::net::Socket::Error | send (fge::net::Packet &packet) |
Send a fge::net::Packet to the connected remote address. | |
fge::net::Socket::Error | sendTo (fge::net::Packet &packet, IpAddress const &remoteAddress, fge::net::Port remotePort) |
Send a fge::net::Packet to the specified address. | |
fge::net::Socket::Error | receiveFrom (fge::net::Packet &packet, fge::net::IpAddress &remoteAddress, fge::net::Port &remotePort) |
Receive a fge::net::Packet from an unspecified remote address. | |
fge::net::Socket::Error | receive (fge::net::Packet &packet) |
Receive a fge::net::Packet from the connected remote address. | |
fge::net::SocketUdp & | operator= (fge::net::SocketUdp &&r) noexcept |
Type | getType () const |
Get the type of the socket. | |
IpAddress::Types | getAddressType () const |
Get the address type of the socket. | |
void | setAddressType (IpAddress::Types type) |
Set the address type of the socket. | |
void | close () |
Close the socket. | |
bool | isValid () const |
Check if the socket is valid. | |
fge::net::Port | getLocalPort () const |
Get the local port of the socket. | |
fge::net::IpAddress | getLocalAddress () const |
Get the local address of the socket. | |
fge::net::Port | getRemotePort () const |
Get the remote port of the socket. | |
fge::net::IpAddress | getRemoteAddress () const |
Get the remote address of the socket. | |
bool | isBlocking () const |
Check if the socket is in blocking mode. | |
Error | setBlocking (bool mode) |
Set the blocking mode of the socket. | |
Error | setReuseAddress (bool mode) |
Set if the socket reuse the address. | |
Error | setBroadcastOption (bool mode) |
Set if the socket support broadcast. | |
Error | select (bool read, uint32_t timeoutms) |
Check the socket for readability or writability. | |
Static Public Member Functions | |
static bool | initSocket () |
Init the low-level socket library. | |
static void | uninitSocket () |
Shutdown the low-level socket library. | |
static int | getPlatformSpecifiedError () |
Get the last platform specific error code. | |
Protected Attributes | |
Type | g_type |
IpAddress::Types | g_addressType {IpAddress::Types::Ipv4} |
SocketDescriptor | g_socket |
bool | g_isBlocking |
A wrapper for UDP sockets inheriting from Socket.
|
inherited |
The error codes.
|
inherited |
The possible types of sockets.
fge::net::Socket::Error fge::net::SocketUdp::bind | ( | fge::net::Port | port, |
IpAddress const & | address ) |
Bind the socket to a local address and port.
From MSDN: The bind function associates a local address and port with a socket.
port | The local port to bind to |
address | The local address to bind to |
|
inherited |
Close the socket.
fge::net::Socket::Error fge::net::SocketUdp::connect | ( | fge::net::IpAddress const & | remoteAddress, |
fge::net::Port | remotePort ) |
Connect the socket to a remote address and port.
From MSDN: For a connectionless socket the operation performed by connect is merely to establish a default destination address that can be used on subsequent send and receive calls. Any datagrams received from an address other than the destination address specified will be discarded.
remoteAddress | The remote address to connect to |
remotePort | The remote port to connect to |
|
overridevirtual |
Create a new socket.
Implements fge::net::Socket.
|
inlinenodiscardinherited |
Get the address type of the socket.
By default, the address type is Ipv4.
|
nodiscardinherited |
Get the local address of the socket.
From MSDN: This function provide the only way to determine the local association that has been set by the system.
|
nodiscardinherited |
Get the local port of the socket.
From MSDN: This function provide the only way to determine the local association that has been set by the system.
|
staticnodiscardinherited |
Get the last platform specific error code.
|
nodiscardinherited |
Get the remote address of the socket.
From MSDN: For datagram sockets, only the address of a peer specified in a previous connect call will be returned. Any address specified by a previous sendto call will not be returned.
|
nodiscardinherited |
Get the remote port of the socket.
From MSDN: For datagram sockets, only the address of a peer specified in a previous connect call will be returned. Any address specified by a previous sendto call will not be returned.
|
inlinenodiscardinherited |
Get the type of the socket.
Type can be one of the type defined in the Socket::Type enum
|
staticinherited |
Init the low-level socket library.
This call WSAStartup() on Windows and nothing on other platforms
|
nodiscardinherited |
Check if the socket is in blocking mode.
|
nodiscardinherited |
Check if the socket is valid.
The socket is valid if it has been created and not closed
fge::net::Socket::Error fge::net::SocketUdp::receive | ( | fge::net::Packet & | packet | ) |
Receive a fge::net::Packet from the connected remote address.
The connect function must be called before calling this function.
packet | The packet to receive into |
fge::net::Socket::Error fge::net::SocketUdp::receive | ( | void * | data, |
std::size_t | size, | ||
std::size_t & | received ) |
Receive data from the connected remote address.
The connect function must be called before calling this function.
data | The data buffer to receive into |
size | The size of the data buffer |
received | The number of bytes received |
fge::net::Socket::Error fge::net::SocketUdp::receiveFrom | ( | fge::net::Packet & | packet, |
fge::net::IpAddress & | remoteAddress, | ||
fge::net::Port & | remotePort ) |
Receive a fge::net::Packet from an unspecified remote address.
packet | The packet to receive into |
remoteAddress | The remote address of the sender |
remotePort | The remote port of the sender |
fge::net::Socket::Error fge::net::SocketUdp::receiveFrom | ( | void * | data, |
std::size_t | size, | ||
std::size_t & | received, | ||
fge::net::IpAddress & | remoteAddress, | ||
fge::net::Port & | remotePort ) |
Receive data from an unspecified remote address.
data | The data buffer to receive into |
size | The size of the data buffer |
received | The number of bytes received |
remoteAddress | The remote address of the sender |
remotePort | The remote port of the sender |
|
inherited |
Check the socket for readability or writability.
From MSDN: The select function allows an application to determine the status of a socket.
If timeout is 0, the function returns immediately (polling).
read | true if the socket should be checked for readability, false otherwise |
timeoutms | The timeout in milliseconds |
fge::net::Socket::Error fge::net::SocketUdp::send | ( | fge::net::Packet & | packet | ) |
Send a fge::net::Packet to the connected remote address.
The connect function must be called before calling this function.
packet | The packet to send |
fge::net::Socket::Error fge::net::SocketUdp::send | ( | void const * | data, |
std::size_t | size ) |
Send data to the connected remote address.
The connect function must be called before calling this function.
data | The data to send |
size | The size of the data to send |
fge::net::Socket::Error fge::net::SocketUdp::sendTo | ( | fge::net::Packet & | packet, |
IpAddress const & | remoteAddress, | ||
fge::net::Port | remotePort ) |
Send a fge::net::Packet to the specified address.
packet | The packet to send |
remoteAddress | The remote address to send to |
remotePort | The remote port to send to |
fge::net::Socket::Error fge::net::SocketUdp::sendTo | ( | void const * | data, |
std::size_t | size, | ||
IpAddress const & | remoteAddress, | ||
fge::net::Port | remotePort ) |
Send data to the specified address.
data | The data to send |
size | The size of the data to send |
remoteAddress | The remote address to send to |
remotePort | The remote port to send to |
|
inherited |
Set the address type of the socket.
When the address type is changed, the socket is closed and recreated.
type | The address type of the socket (Ipv4 or Ipv6) |
|
inherited |
Set the blocking mode of the socket.
mode | The blocking mode to set |
|
inherited |
Set if the socket support broadcast.
From MSDN: The SO_BROADCAST socket option enables the socket to send and receive broadcast messages.
mode | The broadcast mode to set |
|
inherited |
Set if the socket reuse the address.
From MSDN: The SO_REUSEADDR socket option allows the application to bind to an address that is already in use.
mode | The reuse mode to set |
|
staticinherited |
Shutdown the low-level socket library.