SocketUDP wraps a socket using UDP protocol to send data fastly (but with less safety). More...
#include <SocketUDP.hpp>
Public Member Functions | |
SocketUDP () | |
Default constructor. | |
void | SetBlocking (bool blocking) |
Change the blocking state of the socket. | |
bool | Bind (unsigned short port) |
Bind the socket to a specific port. | |
bool | Unbind () |
Unbind the socket from its previous port, if any. | |
Socket::Status | Send (const char *data, std::size_t sizeInBytes, const IPAddress &address, unsigned short port) |
Send an array of bytes. | |
Socket::Status | Receive (char *data, std::size_t maxSize, std::size_t &sizeReceived, IPAddress &address, unsigned short &port) |
Receive an array of bytes. | |
Socket::Status | Send (Packet &packet, const IPAddress &address, unsigned short port) |
Send a packet of data. | |
Socket::Status | Receive (Packet &packet, IPAddress &address, unsigned short &port) |
Receive a packet. | |
bool | Close () |
Close the socket. | |
bool | IsValid () const |
Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK. | |
unsigned short | GetPort () const |
Get the port the socket is currently bound to. | |
bool | operator== (const SocketUDP &other) const |
Comparison operator ==. | |
bool | operator!= (const SocketUDP &other) const |
Comparison operator !=. | |
bool | operator< (const SocketUDP &other) const |
Comparison operator <. | |
Friends | |
class | Selector< SocketUDP > |
SocketUDP wraps a socket using UDP protocol to send data fastly (but with less safety).
Definition at line 45 of file SocketUDP.hpp.
sf::SocketUDP::SocketUDP | ( | ) |
Default constructor.
Definition at line 41 of file SocketUDP.cpp.
bool sf::SocketUDP::Bind | ( | unsigned short | port | ) |
Bind the socket to a specific port.
port | : Port to bind the socket to |
Definition at line 64 of file SocketUDP.cpp.
bool sf::SocketUDP::Close | ( | ) |
Close the socket.
Definition at line 316 of file SocketUDP.cpp.
unsigned short sf::SocketUDP::GetPort | ( | ) | const |
Get the port the socket is currently bound to.
Definition at line 349 of file SocketUDP.cpp.
bool sf::SocketUDP::IsValid | ( | ) | const |
Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.
Definition at line 340 of file SocketUDP.cpp.
bool sf::SocketUDP::operator!= | ( | const SocketUDP & | other | ) | const |
Comparison operator !=.
other | : Socket to compare |
Definition at line 367 of file SocketUDP.cpp.
bool sf::SocketUDP::operator< | ( | const SocketUDP & | other | ) | const |
Comparison operator <.
Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...
other | : Socket to compare |
Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...
Definition at line 378 of file SocketUDP.cpp.
bool sf::SocketUDP::operator== | ( | const SocketUDP & | other | ) | const |
Comparison operator ==.
other | : Socket to compare |
Definition at line 358 of file SocketUDP.cpp.
Socket::Status sf::SocketUDP::Receive | ( | Packet & | packet, | |
IPAddress & | address, | |||
unsigned short & | port | |||
) |
Receive a packet.
This function will block if the socket is blocking
packet | : Packet to fill with received data | |
Address | : Address of the computer which sent the packet | |
Port | : Port on which the remote computer sent the data |
This function will block if the socket is blocking
Definition at line 245 of file SocketUDP.cpp.
Socket::Status sf::SocketUDP::Receive | ( | char * | data, | |
std::size_t | maxSize, | |||
std::size_t & | sizeReceived, | |||
IPAddress & | address, | |||
unsigned short & | port | |||
) |
Receive an array of bytes.
This function will block if the socket is blocking
data | : Pointer to a byte array to fill (make sure it is big enough) | |
maxSize | : Maximum number of bytes to read | |
sizeReceived | : Number of bytes received | |
address | : Address of the computer which sent the data | |
port | : Port on which the remote computer sent the data |
This function will block if the socket is blocking
Definition at line 162 of file SocketUDP.cpp.
Socket::Status sf::SocketUDP::Send | ( | Packet & | packet, | |
const IPAddress & | address, | |||
unsigned short | port | |||
) |
Send a packet of data.
packet | : Packet to send | |
address | : Address of the computer to send the packet to | |
port | : Port to send the data to |
Definition at line 219 of file SocketUDP.cpp.
Socket::Status sf::SocketUDP::Send | ( | const char * | data, | |
std::size_t | sizeInBytes, | |||
const IPAddress & | address, | |||
unsigned short | port | |||
) |
Send an array of bytes.
data | : Pointer to the bytes to send | |
sizeInBytes | : Number of bytes to send | |
address | : Address of the computer to send the packet to | |
port | : Port to send the data to |
Definition at line 118 of file SocketUDP.cpp.
void sf::SocketUDP::SetBlocking | ( | bool | blocking | ) |
Change the blocking state of the socket.
The default behaviour of a socket is blocking
blocking | : Pass true to set the socket as blocking, or false for non-blocking |
Definition at line 50 of file SocketUDP.cpp.
bool sf::SocketUDP::Unbind | ( | ) |
Unbind the socket from its previous port, if any.
Unbind the socket to its previous port.
Definition at line 101 of file SocketUDP.cpp.