C++ boost::Beast错误WebSocket帧有效负载无效utf8

C++ boost::Beast错误WebSocket帧有效负载无效utf8,c++,boost,websocket,boost-asio,boost-beast,C++,Boost,Websocket,Boost Asio,Boost Beast,在异步读取操作期间,将错误传递给回调函数。显示此错误时,将打印以下行 boost::Beast错误WebSocket帧有效负载无效utf8 如何解决这个问题?我通过ws传输二进制数据,不需要将其编码为utf8。最后,如何使客户端发送到服务器的消息有效 发送2条序列化protobuf消息的客户端代码。第一条消息到达,第二条消息崩溃 #include <boost/beast/core.hpp> #include <boost/beast/websocket.hpp> #in

在异步读取操作期间,将错误传递给回调函数。显示此错误时,将打印以下行

boost::Beast错误WebSocket帧有效负载无效utf8

如何解决这个问题?我通过ws传输二进制数据,不需要将其编码为utf8。最后,如何使客户端发送到服务器的消息有效

发送2条序列化protobuf消息的客户端代码。第一条消息到达,第二条消息崩溃

#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
#include "OrderManagement.grpc.pb.h"
namespace beast = boost::beast;      
namespace http = beast::http;          
namespace websocket = beast::websocket; 
namespace net = boost::asio;        
using tcp = boost::asio::ip::tcp;     

    int main(int argc, char** argv)
    {
        try
        {
    
            std::string host = "127.0.0.1";
            std::string port = "8000";
            net::io_context ioc;
            tcp::resolver resolver{ioc};
            websocket::stream<tcp::socket> ws{ioc};
            auto const results = resolver.resolve(host, port);
            auto ep = net::connect(ws.next_layer(), results);
            host += ':' + port;
            ws.set_option(websocket::stream_base::decorator(
                    [](websocket::request_type& req)
                    {
                        req.set(http::field::user_agent,
                                std::string(BOOST_BEAST_VERSION_STRING) +
                                " websocket-client-coro");
                    }));
            
            ws.handshake(host, "/");
            MailTaxi::DriverIdentification identification;
            identification.set_driverid(1);
            identification.set_token("1111111111");
            MailTaxi::Coordinate coordinate;
            coordinate.set_latitude(56.211);
            coordinate.set_longitude(123.21413);
            std::string text("1");
            text[0] = 0x01;
            // Send the message
            ws.write(net::buffer(text + identification.SerializeAsString()));
    
    
            int test = 1;
            while (test) {
                std::cin >> test;
                ws.write(net::buffer(text + coordinate.SerializeAsString()));
            }
            ws.close(websocket::close_code::normal);
        }
    
        catch(std::exception const& e)
        {
            std::cerr << "Error: " << e.what() << std::endl;
            return EXIT_FAILURE;
        }
        return EXIT_SUCCESS;
    }
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“OrderManagement.grpc.pb.h”
名称空间beast=boost::beast;
命名空间http=beast::http;
名称空间websocket=beast::websocket;
名称空间net=boost::asio;
使用tcp=boost::asio::ip::tcp;
int main(int argc,字符**argv)
{
尝试
{
std::string host=“127.0.0.1”;
std::string port=“8000”;
net::io_上下文ioc;
tcp::解析器解析器{ioc};
websocket::流ws{ioc};
auto const results=resolver.resolve(主机、端口);
auto ep=net::connect(ws.next_layer(),results);
主机+=':'+端口;
set_选项(websocket::stream_base::decorator)(
[](websocket::请求类型和请求)
{
请求集(http::field::user\u agent,
std::string(BOOST\u BEAST\u VERSION\u string)+
“websocket客户端coro”);
}));
ws.握手(主机“/”;
MailTaxi::DriverIdentification标识;
标识。设置驱动力(1);
标识。设置令牌(“1111111”);
坐标系;
坐标。设置纬度(56.211);
坐标。设置经度(123.21413);
std::字符串文本(“1”);
文本[0]=0x01;
//发送消息
write(net::buffer(text+identification.SerializeAsString());
int检验=1;
while(测试){
标准:cin>>试验;
write(net::buffer(text+coordinate.SerializeAsString());
}
ws.close(websocket::close\u代码::normal);
}
捕获(标准::异常常量和e)
{

std::cerr您是否发送标记为文本或二进制的消息?请提供@Alan Birtles,这是我用来发送消息的添加的客户端代码。除了发送消息本身的部分之外,代码完全取自官方boost站点上的示例。未标记为二进制的消息,如何执行?