简易asio tcp server

阅读 72

2022-12-01


#include <iostream>
#include "boost/asio.hpp"
using namespace std;
using namespace boost::asio;
io_service G_IOS;

int main() {
ip::tcp::endpoint ep(ip::tcp::v4(), 2110);
ip::tcp::acceptor acceptor(G_IOS, ep);
while (true) {
ip::tcp::socket sock(G_IOS);
acceptor.accept(sock);
cout << "client addr = " << sock.remote_endpoint().address() << endl;
sock.write_some(buffer("hello asio"));
}

return 0;
}

 

精彩评论(0)

0 0 举报