![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A TCP listener. More...
#include <gf/TcpListener.h>
Public Member Functions | |
TcpListener ()=default | |
Default constructor. More... | |
TcpListener (const std::string &service, SocketFamily family=SocketFamily::Unspec) | |
Full constructor. More... | |
TcpSocket | accept () |
Accept a new connection from a remote client. More... | |
TcpSocket | accept (SocketAddress &address) |
Accept a new connection from a remote client. 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 listener.
A TCP listener is a network socket that can handle incoming connections from remote hosts. It can be used to create a TCP server.
The listener is associated to a service. The service can be a port number.
For well-known services, it can also be a name.
A TCP listener is generally created oustide the main loop. Then, for a synchronous server that handles one connection at the time, the listener accept a connection and handle the client.
|
default |
Default constructor.
This constructor creates an invalid listener.
gf::TcpListener::TcpListener | ( | const std::string & | service, |
SocketFamily | family = SocketFamily::Unspec |
||
) |
Full constructor.
This constructor creates a valid listener with an associated service. The service can be a port number (in a string) or a well-known name (such as "http").
service | The service associated to the listener |
family | The socket family of the listener |
TcpSocket gf::TcpListener::accept | ( | ) |
Accept a new connection from a remote client.
This member function blocks until a new connection arrives (unless the socket was made non-blocking). Then a socket is created for the remote client and returned. The returned socket can be used to communicate with the client.
TcpSocket gf::TcpListener::accept | ( | SocketAddress & | address | ) |
Accept a new connection from a remote client.
This member function blocks until a new connection arrives (unless the socket was made non-blocking). Then a socket is created for the remote client and returned. The returned socket can be used to communicate with the client.
In addition, the caller can obtain the socket address of the remote client when it is accepted.
address | A reference to store the socket address of the remote client |