coral
A C++ library for distributed co-simulation
|
A generic server class for simple request-reply protocols. More...
#include "coral/net/reqrep.hpp"
Public Member Functions | |
Server (coral::net::Reactor &reactor, const coral::net::Endpoint &endpoint) | |
Constructs a new server instance bound to the given endpoint, and registers it with the given reactor to wait for incoming requests. | |
void | AddProtocolHandler (const std::string &protocolIdentifier, std::uint16_t protocolVersion, std::shared_ptr< ServerProtocolHandler > handler) |
Adds a protocol handler for the protocol with the given identifier and version. More... | |
coral::net::Endpoint | BoundEndpoint () const |
Returns the endpoint to which the server is bound. More... | |
A generic server class for simple request-reply protocols.
This class receives request messages consisting of 2 or 3 frames. The first frame contains the protocol identifier and version. This is used by the Server to select the appropriate protocol handler, implemented as a ServerProtocolHandler. The second frame is called the message header, while the (optional) third frame is the message body. These are simply forwarded to the protocol handler, whose job it is to formulate a reply message. The reply message has the same format. The Server class takes care of the actual receiving and sending of messages, so the protocol handler only needs to deal with the actual header and body content, and not the details of the network communication.
Multiple clients may connect and send requests to one server.
void coral::net::reqrep::Server::AddProtocolHandler | ( | const std::string & | protocolIdentifier, |
std::uint16_t | protocolVersion, | ||
std::shared_ptr< ServerProtocolHandler > | handler | ||
) |
Adds a protocol handler for the protocol with the given identifier and version.
If a protocol handler supports multiple protocols and/or versions, it may be added more than once.
coral::net::Endpoint coral::net::reqrep::Server::BoundEndpoint | ( | ) | const |
Returns the endpoint to which the server is bound.
This is generally the one that was specified in the constructor, unless the server is bound to a local endpoint (not a proxy), in which case there are two special cases:
*
(i.e., bind on all interfaces), then the returned address will be 0.0.0.0
.*
(i.e., ask the OS for an available emphemeral port), then the actual port will be returned.