boost.asio:demo.

demo1:tcpsocket

十年的赣县网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整赣县建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“赣县网站设计”,“赣县网站推广”以来,每个客户项目都认真落实执行。

#include<iostream> #include<stdexcept> #include<exception> #include<string> #include<fstream> #include<thread> #include<boost/asio.hpp> #include<boost/system/error_code.hpp> #include<boost/system/system_error.hpp> usingnamespaceboost::asio; intmain() { io_serviceservice{}; ip::tcp::endpointend_point{ip::address::from_string("192.168.1.0"),80}; ip::tcp::socketsocket{service}; socket.open(ip::tcp::v4()); socket.connect(end_point); socket.write_some(buffer("GET/indexrn")); std::cout<<"socketavailable:"<<socket.available()<<std::endl; charthe_buffer[1024]{}; std::size_tsize{socket.read_some(buffer(the_buffer,1024))}; std::cout<<"sizeofreading:"<<size<<std::endl; socket.shutdown(ip::tcp::socket::shutdown_receive); socket.close(); std::cout<<the_buffer<<std::endl; return0; }

demo2:udpsocket

#include<iostream> #include<stdexcept> #include<exception> #include<string> #include<fstream> #include<thread> #include<boost/asio.hpp> #include<boost/system/error_code.hpp> #include<boost/system/system_error.hpp> usingnamespaceboost::asio; intmain() { io_serviceservice{}; ip::udp::endpointend_point_receiver{ip::address::from_string("192.168.1.0"),80}; ip::udp::socketsocket{service}; socket.open(ip::udp::v4()); socket.connect(end_point); charthe_buffer[1024]{}; socket.send_to(buffer("testn"),end_point_receiver);//senddatatospecifyaddress(theportis80). ip::udp::endpointend_point_sender{}; std::cout<<"thesenderaddress:"<<end_point_sender.address().to_string()<<std::endl; socket.receive_from(buffer(the_buffer,1024),end_point_sender); std::cout<<"receiveddata:"<<the_buffer<<std::endl; return0; }

demo3:查询域名ip地址.

#include<iostream> #include<stdexcept> #include<exception> #include<string> #include<fstream> #include<thread> #include<boost/asio.hpp> #include<boost/system/error_code.hpp> #include<boost/system/system_error.hpp> usingnamespaceboost::asio; intmain() { io_serviceservice{}; ip::tcp::resolverresolver{service}; ip::tcp::endpointend_point{}; ip::tcp::resolver::iteratorend_point_itr{resolver.resolve(ip::tcp::resolver::query("www.baidu.com","80"))}; std::cout<<end_point_itr->endpoint().address().to_string()<<std::endl; return0; }

本文标题:boost.asio:demo.
转载注明:https://www.cdcxhl.com/article44/cpiihe.html

成都网站建设公司_创新互联,为您提供做网站静态网站网站内链微信小程序网站策划企业建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发