码迷,mamicode.com
首页 > 其他好文 > 详细

udp接收

时间:2016-09-14 23:22:56      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

char receive_buffer[500] = {0};
 
std::vector<std::string> mysplit(std::string str,std::string pattern)
{
    std::string::size_type pos;
    std::vector<std::string> result;
    str+=pattern;//扩展字符串以方便操作
    int size=str.size();
 
    for(int i=0; i<size; i++)
    {
        pos=str.find(pattern,i);
        if(pos<size)
        {
            std::string s=str.substr(i,pos-i);
            result.push_back(s);
            i=pos+pattern.size()-1;
        }
    }
    return result;
}
using boost::asio::ip::udp;
boost::asio::io_service io_service;<br>udp::socket socket(io_service);
boost::asio::ip::udp::endpoint localEndPoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("192.168.1.105"), 6868);
boost::asio::ip::udp::endpoint remoteEndPoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("192.168.1.103"), 6868);
socket.open(localEndPoint.protocol());
socket.bind(localEndPoint);
 
 
size_t len = socket.receive_from(
             boost::asio::buffer(receive_buffer), remoteEndPoint);
std::string str(receive_buffer);
 
std::vector<std::string> out = mysplit(str, ",");

 

udp接收

标签:

原文地址:http://www.cnblogs.com/nmgxbc/p/5873905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!