Class DServer



DServer accepts TCP connections and generates an event for each one. Details on event handling can be found in the Event Handling section. See Simple Server for sample DServer code.

Functions


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.


void setErrorHandler(boost::function<void (string)> errorHandler);

Set an event handler that will be called whenever an error occurs. The errorHandler function will be given a human-readable description of the problem.


bool startListening(boost::function<void (boost::asio::ip::tcp::socket*)> connectHandler)

Start listening for connections. connectHandler will be called whenever a new 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. Returns false on errors and sets errMsg.





















Back to class reference