同步TCP通信服务端

#include <boost/asio.hpp>
#include <iostream>
using namespace boost::asio;
int main()
{
    try
    {
        io_service io;
        ip::tcp::endpoint ep(ip::tcp::v4(), 6688);
        ip::tcp::acceptor acceptor(io, ep);
        while (1)
        {
            ip::tcp::socket sock(io);
            acceptor.accept(sock);
            std::cout << "client:" << sock.remote_endpoint().address() << std::endl;
            sock.write_some(buffer("hello asio"));
        }
    }
    catch (std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }
    return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-11-14
  • 2021-12-24
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-13
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-04-11
相关资源
相似解决方案