boost::asio::io_service io;
GenericServer server(io,12122);
server.onAccept(
[&server](std::shared_ptr<GenericSession> session) {
/* Connection established */
session->onRead([session](rapidjson::Document& d){
/* JSON message read successfully */
rapidjson::StringBuffer s;
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
writer.StartObject();
writer.String("Goodbye");
writer.String(d["hello"].GetString());
writer.EndObject();
session->writeJson(s,[](){
/* JSON message sent successfully */
});
});
session->start();
});
There are several clients shipped as well. For example to connect with and write to the server, you can use the following code.
<?php
require("JsonClient.php");
$session = new Session("127.0.0.1", 12122);
echo $session->execute("{\"hello\":\"world\"}");
?>
If you are running the example server, you get {"Goodbye":"world"} as response.