Websocket 如何使用boost weboscket设置子目录

Websocket 如何使用boost weboscket设置子目录,websocket,beast-websockets,Websocket,Beast Websockets,我想使用boostwebsocket的子脚本 例如,我有s websocket服务器地址,ws://127.0.0.1:5005。 现在我想用ws://127.0.0.1:5005/order替换它。 “order”是websocket中的子目录,可以在libwebsocket中使用。 我找不到有关boost的子脚本的资源。握手方法将目标(您描述的子脚本)作为选项参数 : handshake方法将目标(您描述的子目标)作为选项参数 : 以下是在Boost中为Websocket设置子策略的方法:

我想使用boostwebsocket的子脚本

例如,我有s websocket服务器地址,ws://127.0.0.1:5005。 现在我想用ws://127.0.0.1:5005/order替换它。 “order”是websocket中的子目录,可以在libwebsocket中使用。
我找不到有关boost的子脚本的资源。

握手
方法将目标(您描述的子脚本)作为选项参数

:


handshake
方法将目标(您描述的子目标)作为选项参数

:


以下是在Boost中为Websocket设置子策略的方法:

如果Boost版本>=1.7.0,则:

流ws(ioc);
set_选项(stream_base::decorator)(
[](请求类型和请求)
{
//在请求上设置客户机字段
请求集(boost::beast::http::field::sec_websocket_协议,“protoo”);
请求集(boost::beast::http::field::sec_websocket_version,“13”);
请求集(boost::beast::http::field::sec_websocket_扩展、,
“xxx”);
}));
其他:

流ws(ioc);
ws.handshake_ex(“ws://127.0.0.1:5005”,“/”,
[](请求类型和请求)
{
请求插入(boost::beast::http::field::sec_websocket_协议,“protoo”);
请求插入(boost::beast::http::field::sec_websocket_version,“13”);
请求插入(boost::beast::http::field::sec_websocket_扩展、,
“xxx”);
});

以下是在Boost中为Websocket设置子脚本的方法:

如果Boost版本>=1.7.0,则:

流ws(ioc);
set_选项(stream_base::decorator)(
[](请求类型和请求)
{
//在请求上设置客户机字段
请求集(boost::beast::http::field::sec_websocket_协议,“protoo”);
请求集(boost::beast::http::field::sec_websocket_version,“13”);
请求集(boost::beast::http::field::sec_websocket_扩展、,
“xxx”);
}));
其他:

流ws(ioc);
ws.handshake_ex(“ws://127.0.0.1:5005”,“/”,
[](请求类型和请求)
{
请求插入(boost::beast::http::field::sec_websocket_协议,“protoo”);
请求插入(boost::beast::http::field::sec_websocket_version,“13”);
请求插入(boost::beast::http::field::sec_websocket_扩展、,
“xxx”);
});
// Do the websocket handshake in the client role, on the connected stream.
// The implementation only uses the Host parameter to set the HTTP "Host" field,
// it does not perform any DNS lookup. That must be done first, as shown above.

ws.handshake(
    "www.example.com",  // The Host field
    "/order"            // The request-target
);
stream<tcp_stream> ws(ioc);
ws.set_option(stream_base::decorator(
[](request_type& req)
{
    // Set the client field on the request
    req.set(boost::beast::http::field::sec_websocket_protocol, "protoo");
    req.set(boost::beast::http::field::sec_websocket_version, "13");
    req.set(boost::beast::http::field::sec_websocket_extensions,
            "xxx");
}));
stream<tcp_stream> ws(ioc);
ws.handshake_ex("ws://127.0.0.1:5005", "/",
[](request_type& req)
{
    req.insert(boost::beast::http::field::sec_websocket_protocol, "protoo");
    req.insert(boost::beast::http::field::sec_websocket_version, "13");
    req.insert(boost::beast::http::field::sec_websocket_extensions,
            "xxx");
});