在boost :: asio中发送/接收结构 [英] Sending/receiving a struct in boost::asio

查看:100
本文介绍了在boost :: asio中发送/接收结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!!!

我打算使用boost :: asio :: async_write_some从客户端向服务器发送一个结构,在这种情况下,boost :: serialization和boost :: property_tree来帮助,



Hi!!!
I was going to send a struct from a client to a server using boost::asio::async_write_some, in this case boost::serialization and boost::property_tree come to help,

//boost::serialization
struct blank
{
    int m_id;
    std::string m_message;

    template<typename archive>
    void serialize(archive& ar, const short version)
    {
        ar & m_id;
        ar & m_message;
    }
};

blank info;

info.m_id = 1;
info.m_name = "Rasul";

std::stringstream ss;
boost::archive::binary_oarchive out_archive(ss);

out_archive << info;

那么,现在我如何使用boost :: asio异步发送/接收out_archive ..或



So, now how can I send/receive out_archive using boost::asio asynchronously .. or

//boost::property_tree
boost::property_tree::ptree root;
root.put("id", 2);
root.put("name", "Rasul");



如何使用boost :: asio发送/接收root异步??? (如果您有其他想法请分享)



我尝试过:



i尝试了很多东西,但找不到我的问题的答案。请帮我处理这段代码。谢谢你提前!


How can I send/receive root using boost::asio asynchronously??? (If you have some other ideas please share them)

What I have tried:

i have tried many things, but could not find the answer of my question.Please help me to deal with this code.Thank you in advance!

推荐答案

您的问题已在 Stackoverflow 上得到解答。
Your question is already answered on Stackoverflow.

这篇关于在boost :: asio中发送/接收结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆