![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A TCP socket. More...
#include <gf/TcpSocket.h>
Public Member Functions | |
TcpSocket ()=default | |
Default constructor. More... | |
TcpSocket (const std::string &hostname, const std::string &service, SocketFamily family=SocketFamily::Unspec) | |
Full constructor. More... | |
TcpSocket (const TcpSocket &)=delete | |
Deleted copy constructor. More... | |
TcpSocket & | operator= (const TcpSocket &)=delete |
Deleted copy assignment. More... | |
TcpSocket (TcpSocket &&)=default | |
Default move constructor. More... | |
TcpSocket & | operator= (TcpSocket &&)=default |
Default move assignment. More... | |
~TcpSocket () | |
Destructor. More... | |
SocketAddress | getRemoteAddress () const |
Get the remote address of the host. More... | |
SocketDataResult | sendRawBytes (Span< const uint8_t > buffer) |
Send some bytes over to the socket. More... | |
SocketDataResult | recvRawBytes (Span< uint8_t > buffer) |
Receive some bytes from the socket. More... | |
SocketStatus | sendBytes (Span< const uint8_t > buffer) |
Send a whole buffer to the socket. More... | |
SocketStatus | recvBytes (Span< uint8_t > buffer) |
Receive a whole buffer from the socket. More... | |
SocketStatus | sendPacket (const Packet &packet) |
Send a packet to the socket. More... | |
SocketStatus | recvPacket (Packet &packet) |
Receive a packet from the socket. More... | |
![]() | |
~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 TCP socket.
A TCP socket is a socket for TCP (Transmission Control Protocol). TCP provides a reliable communication between two hosts. TCP is connection-oriented i.e. once the connection is established, it can be used to send and/or receive data until it is shutdown.
|
default |
Default constructor.
This constructor creates an invalid socket
gf::TcpSocket::TcpSocket | ( | const std::string & | hostname, |
const std::string & | service, | ||
SocketFamily | family = SocketFamily::Unspec |
||
) |
Full constructor.
hostname | The name of the host to connect |
service | The service on the host to connect |
family | The prefered socket family |
|
delete |
Deleted copy constructor.
|
default |
Default move constructor.
gf::TcpSocket::~TcpSocket | ( | ) |
Destructor.
The destructor shutdowns the socket before closing it.
SocketAddress gf::TcpSocket::getRemoteAddress | ( | ) | const |
Get the remote address of the host.
SocketStatus gf::TcpSocket::recvBytes | ( | Span< uint8_t > | buffer | ) |
Receive a whole buffer from the socket.
This function ensures the whole buffer is received unless an error occurs.
buffer | The buffer to store the received bytes |
SocketStatus gf::TcpSocket::recvPacket | ( | Packet & | packet | ) |
Receive a packet from the socket.
packet | The packet to store the received bytes |
SocketDataResult gf::TcpSocket::recvRawBytes | ( | Span< uint8_t > | buffer | ) |
Receive some bytes from the socket.
buffer | The buffer to store the received bytes |
SocketStatus gf::TcpSocket::sendBytes | ( | Span< const uint8_t > | buffer | ) |
Send a whole buffer to the socket.
This function ensures the whole buffer is sent unless an error occurs.
buffer | The buffer that contains the bytes to send |
SocketStatus gf::TcpSocket::sendPacket | ( | const Packet & | packet | ) |
Send a packet to the socket.
packet | The packet that contains the bytes to send |
SocketDataResult gf::TcpSocket::sendRawBytes | ( | Span< const uint8_t > | buffer | ) |
Send some bytes over to the socket.
buffer | The buffer that contains the bytes to send |