Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用Boost.Asio读取捕获的整个字符类型数据_C++_Type Conversion_Boost Asio - Fatal编程技术网

C++ 如何使用Boost.Asio读取捕获的整个字符类型数据

C++ 如何使用Boost.Asio读取捕获的整个字符类型数据,c++,type-conversion,boost-asio,C++,Type Conversion,Boost Asio,在与boost::asio合作时,我带着一个有趣的时刻来到阿克罗斯。问题是我想进行语音聊天,并使用OpenAL将捕获的数据保存在ALubyte中: ALubyte* data; // data has the captured data now int data_size; 所以我发送数据将其转换为字符* boost::asio::streambuf m_buf; std::ostream out(&m_buf); out << data_size << ';

在与boost::asio合作时,我带着一个有趣的时刻来到阿克罗斯。问题是我想进行语音聊天,并使用OpenAL将捕获的数据保存在ALubyte中:

ALubyte* data; // data has the captured data now
int data_size; 
所以我发送数据将其转换为字符*

boost::asio::streambuf m_buf;
std::ostream out(&m_buf);
out << data_size << ';'; // the simbol ';' is used to separate data from each other  
out.write((char*)data, data_size);
out << 'q'; // the simbol 'q' is used for a client side to understand that 
            //this is the end of the stream 
            // as a client where the 'out' stream is sent to, 
            //uses boost::async_read_until --> ooops

boost::asio::async_write(client_sock, m_buf, [](){});
伙计们,我知道选择这个函数是我自己的一个大错误,但我现在不能更改它,因为代码有点大 那么,你知道在这种情况下该怎么做,这样我就可以读取所有捕获的数据,还是你认为没有办法
输出而不更改boost::asio::async\u read\u until函数?任何想法都将受到高度赞赏

i除了simbol'q',更好的选择是添加更多类似“cpp”的simbol
在这种情况下,将捕获的数据保存在char类型中的数据可能没有相同的签名,'q'simbols在数据中可能很多,但使用的是“cpp”。。。etc的风险将小于一个“q”simbol,这意味着增加的simbol越多,风险就越小

您不是已经将数据大小作为消息头传递了吗?您不能只读取sizeof(data_size)字节,然后再读取+2(对于;和q)吗?只需选择一个更好的分隔符或使用预先发送的大小即可
//in a client side

boost::asio::streambuf client_buf;
std::istream in(&client_buf);

boost::asio::async_read_until(m_sock, client_buf, 'q', [](){});//---> oooops,   
        // this boost::asio::async_read_until 
        //function reads until the first 'q' simbol which  'data' might 
        //have a lot of 'q' simbol as the captured data is stored as
        // a char type
        //so the function does not read the whole captured data.