Deployed fbd1768 with MkDocs version: 1.1.2

This commit is contained in:
2020-07-08 19:14:25 +00:00
parent ddf992a03c
commit 3d4ecc4501
6 changed files with 30 additions and 18 deletions

View File

@ -340,28 +340,31 @@ ix::WebSocketServer server(port);
server.setOnConnectionCallback(
[&server](std::shared_ptr<WebSocket> webSocket,
std::shared_ptr<ConnectionState> connectionState)
std::shared_ptr<ConnectionState> connectionState,
std::unique_ptr<ConnectionInfo> connectionInfo)
{
std::cout << "Remote ip: " << connectionInfo->remoteIp << std::endl;
webSocket->setOnMessageCallback(
[webSocket, connectionState, &server](const ix::WebSocketMessagePtr msg)
{
if (msg->type == ix::WebSocketMessageType::Open)
{
std::cerr << "New connection" << std::endl;
std::cout << "New connection" << std::endl;
// A connection state object is available, and has a default id
// You can subclass ConnectionState and pass an alternate factory
// to override it. It is useful if you want to store custom
// attributes per connection (authenticated bool flag, attributes, etc...)
std::cerr << "id: " << connectionState->getId() << std::endl;
std::cout << "id: " << connectionState->getId() << std::endl;
// The uri the client did connect to.
std::cerr << "Uri: " << msg->openInfo.uri << std::endl;
std::cout << "Uri: " << msg->openInfo.uri << std::endl;
std::cerr << "Headers:" << std::endl;
std::cout << "Headers:" << std::endl;
for (auto it : msg->openInfo.headers)
{
std::cerr << it.first << ": " << it.second << std::endl;
std::cout << it.first << ": " << it.second << std::endl;
}
}
else if (msg->type == ix::WebSocketMessageType::Message)
@ -493,11 +496,14 @@ server.wait();
<p>If you want to handle how requests are processed, implement the setOnConnectionCallback callback, which takes an HttpRequestPtr as input, and returns an HttpResponsePtr. You can look at HttpServer::setDefaultConnectionCallback for a slightly more advanced callback example.</p>
<pre><code class="cpp">setOnConnectionCallback(
[this](HttpRequestPtr request,
std::shared_ptr&lt;ConnectionState&gt; /*connectionState*/) -&gt; HttpResponsePtr
std::shared_ptr&lt;ConnectionState&gt; /*connectionState*/,
std::unique_ptr&lt;ConnectionInfo&gt; connectionInfo) -&gt; HttpResponsePtr
{
// Build a string for the response
std::stringstream ss;
ss &lt;&lt; request-&gt;method
ss &lt;&lt; connectionInfo-&gt;remoteIp
&lt;&lt; &quot; &quot;
&lt;&lt; request-&gt;method
&lt;&lt; &quot; &quot;
&lt;&lt; request-&gt;uri;