Mooon-server provides a common TCP framework and abstracts the Ipackethandler interface for packet parsing, which provides unrestricted latitude, supports any protocol, but increases the complexity of the usage.
Because most protocols will define a large small segment of the message packet, based on this premise, mooon-server references the new interface Imessageobserver, which can parse any message that the header is Net::tcommonmessageheader. After a package parsing is complete (both headers and packages have received completion), the message is passed to the consumer by a callback On_message (), which greatly simplifies the mooon-server programming.
The following is the definition of an interface:
/*** * Message Viewer * Call if you receive a full message * If your message header and Net::tcommonmessageheader are consistent, * then suggest using imessageobserver instead of Ipackethandler, * Imessageobserver is a higher level interface than Ipackethandler/class Callback_interface Imessageobserver {public:virtual ~IMessage Observer () {}/*** * received a full message when the callback * @request_header input parameters, received the message header * @request_body input parameters, received Message body * Here it is necessary to note that the framework does not release request_body memory and requires the user to release the * Release method: delete []request_body; otherwise there will be a memory leak * @re
Sponse_buffer output parameters, sent to the end-to-end response, the default value is NULL * Please note that *response_buffer must be new char[], * and will be delete by frame [] it * @response_size output parameter, the number of response data bytes that need to be sent to the end, the default value is 0 * @return processing successfully returns TRUE, otherwise return FALSE */virtual bool on
_message (const net::tcommonmessageheader& request_header, const char* Request_body
, char** Response_buffer, size_t* response_sizer) = 0; /***
*Connection is turned off/virtual void on_connection_closed () {}/*** * Connection Timeout * @return If true, confirm that Connection timeout, connection will be closed *; otherwise, the connection will continue to be used, while the timestamp will be updated/virtual bool On_connection_timeout () {RET
Urn true; /*** * Packet sent after the callback * @return Util::handle_continue means not to close the connection to continue to use, * return to other values will close the connection/Virtu Al util::handle_result_t on_response_completed () {//return util::handle_close;//Short connection return Util::handle_continue; Long connection};
This article is from the "Flying Month" blog, please be sure to keep this source http://mooon.blog.51cto.com/1246491/941084