首页 > 代码库 > 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接收
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。