首页 > 代码库 > udp接收

udp接收

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接收