Preface: add the downstream data
1. Implement the handle function as follows:
# Include "jsoncpp/JSON. H"
# Include "downstreamhandler. H"
Void downstreamhandler: handle (clientsession * client, const char * pack, int length ){
JSON: Value V;
JSON: reader;
If (reader. parse (pack, V )){
Int uri = V ["Uri"]. asuint ();
STD: String MSG = V ["MSG"]. asstring ();
# Ifdef open_log
Printf ("[downstreamhandler: handle] URI is % d \ n", Uri );
Printf ("[downstreamhandler: handle] MSG is % s \ n", MSG. c_str ());
# Endif
Switch (URI ){
Case ploginres:
Onloginres (client, pack, length );
Break;
Case ppingres:
Onpingres (client, pack, length );
Break;
Default:
Printf ("[downstreamhandler: handle] unknown URI: % d \ n", Uri );
Break;
}
}
}
2. Implementation of the login information response function:
Void downstreamhandler: onloginres (clientsession * client, const char * pack, int length ){
# Ifdef open_log
Printf ("[downstreamhandler: onloginres] ~~~~~~~~~ Invoke ~~~~~~~~~ \ N ");
# Endif
JSON: Value JV;
JSON: fastwriter writer;
Int uri = 3;
STD: String MSG = "USTC ";
JV ["Uri"] = JSON: Value (URI );
JV ["MSG"] = JSON: Value (MSG );
STD: String loginres = writer. Write (jv );
Client-> senddata (loginres );
}
Description: JSON is an open-source library that returns response information in JSON format.
3. Implement the ping heartbeat response function as follows:
Void downstreamhandler: onpingres (clientsession * client, const char * pack, int length ){
# Ifdef open_log
Printf ("[downstreamhandler: onpingres] ~~~~~~~~~ Invoke ~~~~~~~~~ \ N ");
# Endif
JSON: Value JV;
JSON: fastwriter writer;
Int uri = 5;
STD: String MSG = "linyanwen ";
JV ["Uri"] = JSON: Value (URI );
JV ["MSG"] = JSON: Value (MSG );
STD: String pingres = writer. Write (jv );
Client-> senddata (pingres );
}
Description: JSON is an open-source library that returns response information in JSON format.
~ To be continued
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8315883