udp接收
Posted GIS开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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接收的主要内容,如果未能解决你的问题,请参考以下文章