The Micro C++ Library
|
A ServerSocket represents a Transmission Control Protocol (TCP) server endpoint of a StreamSocket. It adds the capability to listen for and to accept other TCP client connections. More...
#include <micxx.hxx>
Inherits micxx::Socket.
Inherited by micxx::SSLServerSocket.
Public Member Functions | |
ServerSocket () | |
Create a new unbound, disconnected ServerSocket. | |
virtual ClientSocket * | accept () |
Accept a new ClientSocket connection. | |
virtual void | bind (unsigned short port) |
virtual void | bind (const SocketAddress &socketAddress) |
virtual int | getBacklog () const |
The backlog defines the maximum length for the (underlying) queue of pending connections. | |
virtual void | listen (int abacklog=SOMAXCONN) |
Start listening for incoming ClientSocket connections. | |
virtual std::string | toString () const |
Returns a printable representation. | |
Protected Member Functions | |
virtual ClientSocket * | createSocket (socket_t rawSocket, SocketAddress *socketAddress) |
Create a ClientSocket instance during accept(). |
A ServerSocket represents a Transmission Control Protocol (TCP) server endpoint of a StreamSocket. It adds the capability to listen for and to accept other TCP client connections.
Example:
#include <micxx.hxx> micxx::ServerSocket serverSocket; serverSocket.bind(8000); serverSocket.listen(); while (true) { micxx::AutoPtr<micxx::ClientSocket> socket = serverSocket.accept(); ... socket->recv(...); socket->send(...); ... }
micxx::ServerSocket::ServerSocket | ( | ) |
Create a new unbound, disconnected ServerSocket.
virtual ClientSocket* micxx::ServerSocket::accept | ( | ) | [virtual] |
Accept a new ClientSocket connection.
virtual void micxx::ServerSocket::bind | ( | unsigned short | port | ) | [virtual] |
virtual void micxx::ServerSocket::bind | ( | const SocketAddress & | socketAddress | ) | [virtual] |
Reimplemented from micxx::Socket.
virtual ClientSocket* micxx::ServerSocket::createSocket | ( | socket_t | rawSocket, |
SocketAddress * | socketAddress | ||
) | [protected, virtual] |
Create a ClientSocket instance during accept().
This implementation just returns a ClientSocket. Derived classes may overwrite this method to return instances derived from ClientSocket.
rawSocket | the socket descriptor |
socketAddress | the socket address to be used internally. The new socket takes ownership of the allocated SocketAdress and gets responsible for deleting it. In any case the implementation is responsible for deleting it. |
Reimplemented in micxx::SSLServerSocket.
virtual int micxx::ServerSocket::getBacklog | ( | ) | const [virtual] |
The backlog defines the maximum length for the (underlying) queue of pending connections.
If a connection request arrives with the queue full, the client may receive an error with an indication of ECONNREFUSED
.
SOMAXCONN
. virtual void micxx::ServerSocket::listen | ( | int | abacklog = SOMAXCONN | ) | [virtual] |
Start listening for incoming ClientSocket connections.
To accept connections, a ServerSocket is first allocated and bound to a local address with the one of the functions bind(unsigned short) or bind(const SocketAddress&). Optionally a backlog for incoming connections is specified (otherwise the default SOMAXCONN
is used), and then the connections are accepted with accept().
abacklog | The abacklog parameter defines the maximum length for the (underlying) queue of pending connections. |
virtual std::string micxx::ServerSocket::toString | ( | ) | const [virtual] |
Returns a printable representation.
Reimplemented from micxx::Socket.