小编Abh*_*yed的帖子

Boost-beast websocket 握手问题

我正在尝试与远程服务器建立 websocket 连接并收到以下错误:WebSocket 握手被远程对等方拒绝

我正在关注这个例子:https : //www.boost.org/doc/libs/1_70_0/libs/beast/example/websocket/client/sync/websocket_client_sync.cpp

对于以下服务器:https : //api.hitbtc.com/#socket-api-reference

提前感谢您的帮助!

int main(int argc, char** argv) {
    try
    {
        auto const host = "api.hitbtc.com";
        auto const port = "443";

        net::io_context ioc;
        tcp::resolver resolver{ ioc };
        websocket::stream<tcp::socket> ws{ ioc };

        auto const results = resolver.resolve(host, port);

        net::connect(ws.next_layer(), results.begin(), results.end());

        // Perform the websocket handshake - this is where i presume the issue is.
        ws.handshake(host, "/api/2/ws");

        beast::flat_buffer buffer;
        ws.read(buffer);
        ws.close(websocket::close_code::normal);
        std::cout << beast::make_printable(buffer.data()) << std::endl;
    }
    catch (std::exception const& e) …
Run Code Online (Sandbox Code Playgroud)

c++ boost beast-websockets boost-beast

4
推荐指数
1
解决办法
3681
查看次数

标签 统计

beast-websockets ×1

boost ×1

boost-beast ×1

c++ ×1