728x90
반응형
Daytime.1 소스 (Source listing for Daytime.1)
//
// client.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main(int argc, char* argv[])
{
try
{
if (argc != 2)
{
std::cerr << "Usage: client <host>" << std::endl;
return 1;
}
boost::asio::io_context io_context;
tcp::resolver resolver(io_context);
tcp::resolver::results_type endpoints =
resolver.resolve(argv[1], "daytime");
tcp::socket socket(io_context);
boost::asio::connect(socket, endpoints);
for (;;)
{
boost::array<char, 128> buf;
boost::system::error_code error;
size_t len = socket.read_some(boost::asio::buffer(buf), error);
if (error == boost::asio::error::eof)
break; // Connection closed cleanly by peer.
else if (error)
throw boost::system::system_error(error); // Some other error.
std::cout.write(buf.data(), len);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
728x90
반응형
'Boost C++ Libraries > Boost.Asio' 카테고리의 다른 글
Boost.Asio 튜토리얼 - Daytime.2 소스 (0) | 2020.12.16 |
---|---|
Boost.Asio 튜토리얼 - Daytime.2 - 동기식 TCP daytime 서버 (0) | 2020.12.16 |
Boost.Asio 튜토리얼 - Daytime.1 - 동기식 TCP daytime 클라이언트 (0) | 2020.12.16 |
Boost.Asio 튜토리얼 - Timer.5 소스 (0) | 2020.12.16 |
Boost.Asio 튜토리얼 - Timer.5 - 멀티스레드 프로그램에서 핸들러 동기화 (0) | 2020.12.15 |