Ocean
Ocean::Network::TCPServer Class Reference

This class implements a TCP server. More...

Inheritance diagram for Ocean::Network::TCPServer:

Public Member Functions

 TCPServer ()
 Creates a new TCP server. More...
 
 ~TCPServer () override
 Destructs a TCP server. More...
 
bool start () override
 Starts the server. More...
 
bool disconnect (const ConnectionId connection) override
 Disconnects a specified connection. More...
 
- 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. More...
 
virtual SocketResult send (const ConnectionId connectionId, const std::string &message)
 Sends a message over a specified connection. More...
 
virtual size_t connections () const
 Returns the number of active connections of this server. More...
 
bool connectionProperties (const ConnectionId connectionId, Address4 &address, Port &port)
 Returns the remote address and port of a specified connection. More...
 
void setConnectionRequestCallback (const ConnectionRequestCallback &callback)
 Sets the connection request callback function. More...
 
void setDisconnectCallback (const DisconnectCallback &callback)
 Sets the disconnect callback function. More...
 
void setReceiveCallback (const ReceiveCallback &callback)
 Sets the receive callback function. More...
 
- Public Member Functions inherited from Ocean::Network::Server
 ~Server () override
 Destructs a server object. More...
 
virtual bool stop ()
 Stops the server. More...
 
- Public Member Functions inherited from Ocean::Network::Socket
virtual ~Socket ()
 Destructs a socket object. More...
 
SocketId id () const
 Returns the socket id. More...
 
Address4 address () const
 Returns the own address of this socket. More...
 
Port port () const
 Returns the own port of this socket. More...
 
virtual bool setAddress (const Address4 &address)
 Sets the own address of this socket. More...
 
virtual bool setPort (const Port &port)
 Sets the own port of this socket. More...
 
 operator bool () const
 Returns whether this socket is valid. More...
 

Protected Member Functions

bool buildSocket ()
 Builds the TCP socket. More...
 
- Protected Member Functions inherited from Ocean::Network::ConnectionOrientedServer
 ConnectionOrientedServer ()
 Creates a new connection oriented server. More...
 
 ~ConnectionOrientedServer () override
 Destructs a connection oriented server. More...
 
bool onScheduler () override
 The scheduler event function. More...
 
virtual size_t onSend (const ConnectionId connectionId, const void *data, const size_t size)
 Internal event function to send data. More...
 
virtual void onReceived (const ConnectionId connectionId, const void *data, const size_t size)
 Internal event function for received data. More...
 
- Protected Member Functions inherited from Ocean::Network::Server
 Server ()
 Creates a new server object. More...
 
- Protected Member Functions inherited from Ocean::Network::Socket
 Socket ()
 Creates a new socket object. More...
 
 Socket (const Socket &object)=delete
 Disabled copy constructor. More...
 
bool setBlockingMode (const bool blocking)
 Sets the blocking mode of this socket. More...
 
size_t maximalMessageSize (const size_t defaultSize=65536)
 Returns the maximal message size in bytes. More...
 
bool releaseSocket ()
 Releases the socket. More...
 
Socketoperator= (const Socket &object)=delete
 Disabled copy operator. More...
 

Additional Inherited Members

- Public Types inherited from Ocean::Network::ConnectionOrientedServer
typedef unsigned int ConnectionId
 Definition of a connection id. More...
 
typedef Callback< bool, const Address4 &, const Port &, const ConnectionIdConnectionRequestCallback
 Definition of a connection request callback function. More...
 
typedef Callback< void, const ConnectionIdDisconnectCallback
 Definition of a disconnect callback function. More...
 
typedef Callback< void, const ConnectionId, const void *, const size_t > ReceiveCallback
 Definition of a receive callback function. More...
 
- 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...
 
typedef SOCKET SocketId
 Definition of a socket id. More...
 
typedef int SocketId
 Definition of a socket id. More...
 
typedef std::vector< uint8_t > Buffer
 Definition of a vector holding 8 bit values. More...
 
- Static Public Member Functions inherited from Ocean::Network::ConnectionOrientedServer
static constexpr ConnectionId invalidConnectionId ()
 Returns an invalid connection id. More...
 
- Static Public Member Functions inherited from Ocean::Network::Socket
static constexpr SocketId invalidSocketId ()
 Returns an invalid socket id. More...
 
static bool setBlockingMode (const SocketId socketId, const bool blocking)
 Sets the blocking mode of a socket. More...
 
- Protected Types inherited from Ocean::Network::ConnectionOrientedServer
typedef std::unordered_map< ConnectionId, ConnectionObjectConnectionMap
 Definition of a map mapping connection ids to sockets. More...
 
- Protected Attributes inherited from Ocean::Network::ConnectionOrientedServer
ConnectionMap connectionMap_
 Map holding all valid connections. More...
 
ConnectionId connectionCounter_ = ConnectionId(invalidConnectionId() + 1)
 Connection counter. More...
 
ConnectionRequestCallback connectionRequestCallback_
 Connection request callback function. More...
 
DisconnectCallback disconnectCallback_
 Disconnect callback function. More...
 
ReceiveCallback receiveCallback_
 Receive callback function. More...
 
- Protected Attributes inherited from Ocean::Network::Server
Buffer buffer_
 The socket buffer of this server. More...
 
bool schedulerIsActive_ = false
 True, if the server scheduler is active. More...
 
- Protected Attributes inherited from Ocean::Network::Socket
SocketId socketId_ = invalidSocketId()
 Socket id. More...
 
Lock lock_
 Socket lock. More...
 
NetworkResource networkResource_
 The network resource object. More...
 

Detailed Description

This class implements a TCP server.

Constructor & Destructor Documentation

◆ TCPServer()

Ocean::Network::TCPServer::TCPServer ( )

Creates a new TCP server.

◆ ~TCPServer()

Ocean::Network::TCPServer::~TCPServer ( )
override

Destructs a TCP server.

Member Function Documentation

◆ buildSocket()

bool Ocean::Network::TCPServer::buildSocket ( )
protected

Builds the TCP socket.

Returns
True, if succeeded

◆ disconnect()

bool Ocean::Network::TCPServer::disconnect ( const ConnectionId  connection)
overridevirtual

Disconnects a specified connection.

See also
ConnectionOrientedServer::disconnect().

Implements Ocean::Network::ConnectionOrientedServer.

◆ start()

bool Ocean::Network::TCPServer::start ( )
overridevirtual

Starts the server.

Beware: If a specific listening port is expected the own port has to be set before

See also
Server::start().

Reimplemented from Ocean::Network::Server.


The documentation for this class was generated from the following file: