相关文章推荐

1. socket.local_endpoint()  返回的ip是 "0.0.0.0", 而不是本机IP地址,要获取本机IP请参考:

tcp::resolver resolver(io_service);
tcp::resolver::query query(host_name(), "");
tcp::resolver::iterator iter = resolver.resolve(query);

2. io_service.run()阻塞问题

Actually, io_service.run() blocks if it has "work" to do. In general, "work" means an unfinished asynchronous operation.
也就是说,如果没有任何异步操作,io_service.run()就会停止。因此,io_service.run()需要在第一个异步操作之后启动。