|
Ocean
|
This class implements a TCP server. More...
#include <TCPServer.h>
Public Member Functions | |
| TCPServer () | |
| Creates a new TCP server. | |
| ~TCPServer () override | |
| Destructs a TCP server. | |
| bool | start () override |
| Starts the server. | |
| bool | disconnect (const ConnectionId connection) override |
| Disconnects a specified connection. | |
Public Member Functions inherited from Ocean::Network::ConnectionOrientedServer | |
| virtual SocketResult | send (const ConnectionId connectionId, const void *data, const size_t size) |
| Sends data over a specified connection. | |
| virtual SocketResult | send (const ConnectionId connectionId, const std::string &message) |
| Sends a message over a specified connection. | |
| virtual size_t | connections () const |
| Returns the number of active connections of this server. | |
| bool | connectionProperties (const ConnectionId connectionId, Address4 &address, Port &port) |
| Returns the remote address and port of a specified connection. | |
| void | setConnectionRequestCallback (const ConnectionRequestCallback &callback) |
| Sets the connection request callback function. | |
| void | setDisconnectCallback (const DisconnectCallback &callback) |
| Sets the disconnect callback function. | |
| void | setReceiveCallback (const ReceiveCallback &callback) |
| Sets the receive callback function. | |
Public Member Functions inherited from Ocean::Network::Server | |
| ~Server () override | |
| Destructs a server object. | |
| virtual bool | stop () |
| Stops the server. | |
Public Member Functions inherited from Ocean::Network::Socket | |
| virtual | ~Socket () |
| Destructs a socket object. | |
| SocketId | id () const |
| Returns the socket id. | |
| Address4 | address () const |
| Returns the own address of this socket. | |
| Port | port () const |
| Returns the own port of this socket. | |
| virtual bool | setAddress (const Address4 &address) |
| Sets the own address of this socket. | |
| virtual bool | setPort (const Port &port) |
| Sets the own port of this socket. | |
| operator bool () const | |
| Returns whether this socket is valid. | |
Protected Member Functions | |
| bool | buildSocket () |
| Builds the TCP socket. | |
Protected Member Functions inherited from Ocean::Network::ConnectionOrientedServer | |
| ConnectionOrientedServer () | |
| Creates a new connection oriented server. | |
| ~ConnectionOrientedServer () override | |
| Destructs a connection oriented server. | |
| bool | onScheduler () override |
| The scheduler event function. | |
| virtual size_t | onSend (const ConnectionId connectionId, const void *data, const size_t size) |
| Internal event function to send data. | |
| virtual void | onReceived (const ConnectionId connectionId, const void *data, const size_t size) |
| Internal event function for received data. | |
Protected Member Functions inherited from Ocean::Network::Server | |
| Server () | |
| Creates a new server object. | |
Protected Member Functions inherited from Ocean::Network::Socket | |
| Socket () | |
| Creates a new socket object. | |
| Socket (const Socket &object)=delete | |
| Disabled copy constructor. | |
| bool | setBlockingMode (const bool blocking) |
| Sets the blocking mode of this socket. | |
| size_t | maximalMessageSize (const size_t defaultSize=65536) |
| Returns the maximal message size in bytes. | |
| bool | releaseSocket () |
| Releases the socket. | |
| Socket & | operator= (const Socket &object)=delete |
| Disabled copy operator. | |
Additional Inherited Members | |
Public Types inherited from Ocean::Network::ConnectionOrientedServer | |
| using | ConnectionId = unsigned int |
| Definition of a connection id. | |
| using | ConnectionRequestCallback = Callback< bool, const Address4 &, const Port &, const ConnectionId > |
| Definition of a connection request callback function. | |
| using | DisconnectCallback = Callback< void, const ConnectionId > |
| Definition of a disconnect callback function. | |
| using | ReceiveCallback = Callback< void, const ConnectionId, const void *, const size_t > |
| Definition of a receive callback function. | |
Public Types inherited from Ocean::Network::Socket | |
| enum | SocketResult { SR_SUCCEEDED = 0 , SR_FAILED , SR_BUSY , SR_NOT_CONNECTED } |
| Definition of individual result values. More... | |
| using | SocketId = SOCKET |
| Definition of a socket id. | |
| using | SocketId = int |
| Definition of a socket id. | |
| using | Buffer = std::vector< uint8_t > |
| Definition of a vector holding 8 bit values. | |
Static Public Member Functions inherited from Ocean::Network::ConnectionOrientedServer | |
| static constexpr ConnectionId | invalidConnectionId () |
| Returns an invalid connection id. | |
Static Public Member Functions inherited from Ocean::Network::Socket | |
| static constexpr SocketId | invalidSocketId () |
| Returns an invalid socket id. | |
| static bool | setBlockingMode (const SocketId socketId, const bool blocking) |
| Sets the blocking mode of a socket. | |
Protected Types inherited from Ocean::Network::ConnectionOrientedServer | |
| using | ConnectionMap = std::unordered_map< ConnectionId, ConnectionObject > |
| Definition of a map mapping connection ids to sockets. | |
Protected Attributes inherited from Ocean::Network::ConnectionOrientedServer | |
| ConnectionMap | connectionMap_ |
| Map holding all valid connections. | |
| ConnectionId | connectionCounter_ = ConnectionId(invalidConnectionId() + 1) |
| Connection counter. | |
| ConnectionRequestCallback | connectionRequestCallback_ |
| Connection request callback function. | |
| DisconnectCallback | disconnectCallback_ |
| Disconnect callback function. | |
| ReceiveCallback | receiveCallback_ |
| Receive callback function. | |
Protected Attributes inherited from Ocean::Network::Server | |
| Buffer | buffer_ |
| The socket buffer of this server. | |
| bool | schedulerIsActive_ = false |
| True, if the server scheduler is active. | |
Protected Attributes inherited from Ocean::Network::Socket | |
| SocketId | socketId_ = invalidSocketId() |
| Socket id. | |
| Lock | lock_ |
| Socket lock. | |
| NetworkResource | networkResource_ |
| The network resource object. | |
This class implements a TCP server.
| Ocean::Network::TCPServer::TCPServer | ( | ) |
Creates a new TCP server.
|
override |
Destructs a TCP server.
|
protected |
Builds the TCP socket.
|
overridevirtual |
Disconnects a specified connection.
Implements Ocean::Network::ConnectionOrientedServer.
|
overridevirtual |
Starts the server.
Beware: If a specific listening port is expected the own port has to be set before
Reimplemented from Ocean::Network::Server.