#include <socket.hpp>
Public Member Functions | |
Socket (const std::string &ipAddress, uint16_t port, SocketType type=SocketType::UNKNOWN) | |
virtual | ~Socket () noexcept |
virtual void | bind () |
virtual void | connect () |
virtual void | listen () |
virtual void | accept (Socket &socket) |
virtual void | send (const std::string &message)=0 |
virtual void | receive (std::string &message)=0 |
virtual void | receive () |
virtual void | shutdown (Direction how=Direction::BOTH) |
virtual void | close () noexcept |
virtual int | getDomain () const =0 |
virtual int | getType () const =0 |
const std::string & | getIpAddress () const |
void | setIpAddress (const std::string &ipAddress) |
uint16_t | getPort () const |
void | setIpAddress (uint16_t port) |
anch::network::SocketType | getSocketType () const |
void | setSocketType (SocketType type) |
int | getBacklog () const |
void | setBacklog (int backlog) |
![]() | |
Observable () | |
virtual | ~Observable () |
bool | addObserver (anch::events::Observer< SocketEvent > &observer) |
void | removeObserver (anch::events::Observer< SocketEvent > &observer) |
void | notifyObservers (const SocketEvent &event, const std::map< std::string, std::string > &headers={}) |
void | notifyObservers (const anch::events::Event< SocketEvent > &event) |
Protected Member Functions | |
Socket (SocketType type) | |
Protected Attributes | |
SOCKET | _sock |
int | _backlog |
addrinfo * | _address |
Network socket management class
|
protected |
Socket constructor.
type | The socket type |
anch::network::Socket::Socket | ( | const std::string & | ipAddress, |
uint16_t | port, | ||
SocketType | type = SocketType::UNKNOWN ) |
Socket constructor.
Backlog is set to 5 by default. You can change it using the setter before call listen method.
ipAddress | IP address |
port | Destination port |
type | The socket type |
anch::network::IOException | Error while creating the socket |
|
virtualnoexcept |
Socket destructor
|
virtual |
Accept client connection
socket | The socket which describes client connection |
anch::network::IOException | Error while accepting client connection |
Reimplemented in anch::network::UdpSocket.
|
virtual |
Bind socket
anch::network::IOException | Error while binding the socket |
|
virtualnoexcept |
Close the socket
|
virtual |
Connect to remote socket
anch::network::IOException | Error while connectin the client socket to the server socket |
Reimplemented in anch::network::UdpSocket.
|
inline |
Backlog getter
|
pure virtual |
Get the socket domain
Implemented in anch::network::UdpSocket.
|
inline |
IP address getter
|
inline |
Destination port getter
|
inline |
Socket type getter
|
pure virtual |
Get the socket service type
Implemented in anch::network::UdpSocket.
|
virtual |
Listen on socket
anch::network::IOException | Error while listening on the socket |
Reimplemented in anch::network::UdpSocket.
|
virtual |
Receive a message on socket
anch::network::IOException | Network error while receiving message |
|
pure virtual |
Receive a message on socket
message | The messages which has been received |
anch::network::IOException | Network error while receiving message |
Implemented in anch::network::TcpSocket, and anch::network::UdpSocket.
|
pure virtual |
Send a message on socket
message | The message to send |
anch::network::IOException | Network error while sending message |
Implemented in anch::network::TcpSocket, and anch::network::UdpSocket.
|
inline |
Backlog setter
backlog | The backlog to set |
|
inline |
IP address setter
ipAddress | The IP address to set |
|
inline |
Destination port setter
port | The destination port to set |
|
inline |
Socket type setter
type | The socket type to set |
|
virtual |
Shutdown data flow between client and server.
This method has to be called by server.
how | Direction of the data flow which has to be closed |
anch::network::IOException | Network error while shutting down data transfer |
|
protected |
The address informations
|
protected |
The number of connection in waiting state
|
protected |
The socket