Class DServer



DServer accepts TCP connections and generates an event for each one. DServer is an abstract class, and should be inherited by a child that implements its event handlers. See Simple Server for sample DServer code.

Functions

Event Handlers


DServer(DEngine *engine)

The constructor registers this DServer with the given engine.


bool bind(IpVersion ipVersion, uint16_t portNumber)

Binds the server to the specified portNumber. ipVersion should be set to either DA_IPV4 or DA_IPV6. This function returns false if it couldn't bind the socket, and sets errMsg with a description of the problem.


void close(void)

Closes the listen socket.


string getErrMsg(void)

Returns a description of the most recent error.


bool startListening(void)

Start listening for connections. connectHandler will be called whenever a client connects. Returns false on errors and sets errMsg.


virtual void connectHandler(boost::asio::ip::tcp::socket *socket) = 0

This event handler is called when a client connects. socket can be used to construct a DClient, which will handle the connection. If you prefer to use socket directly, you are responsible for deleting it when finished.


virtual void errorHandler(string errorDesc) = 0

An event handler that's called when there's an error accepting connections. errorDesc contains a description of the problem.











Back to class reference