`
mylove2060
  • 浏览: 330756 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Boost - Socket连接(获取本地IP和远程IP)

阅读更多

Author:QQ174554431


#include "stdafx.h"
#include <iostream>
#include <boost/asio/io_service.hpp>
#include <boost/asio.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
	try
	{
		boost::asio::io_service io_service;
		boost::asio::ip::tcp::socket socket(io_service);
		socket.connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("10.10.90.121"),11111));

		std::cout<<socket.local_endpoint().address().to_string()<<std::endl; 
		//my local ip address  10.10.118.140
		std::cout<<socket.remote_endpoint().address().to_string()<<std::endl;
		//10.10.90.121
	}
	catch(std::exception& e)
	{
		std::cerr<<e.what()<<std::endl;
	}
	return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics