用asio写网络,简直是种享受啊,贴出来交流交流,代码直接拷到新工程的main.cpp里编译就行了
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/asio.hpp>
using namespace boost::asio;
#include <boost/system/error_code.hpp>
using boost::system::error_code;
#include <boost/bind.hpp>
using boost::bind;
#include <iostream>
using std::cout;
using std::endl;
#include <cstring>
using std::strcmp;
#include <cstdlib>
using std::atoi;
typedef boost::shared_ptr<ip::tcp::socket> socket_sp;
void conn_handler(socket_sp sock, ip::tcp::endpoint ep, const error_code& ec)
{
if (!ec)
{
cout << ep.address().to_string() << ":" << ep.port() << endl;
}
if (ec != error::operation_aborted)
{
sock->close();
}
}
void scan_ip(const char* start, const char* end, unsigned short port)
{
unsigned long s = ntohl(ine