부스트를 배우고 주간 서버 클라이언트를 example으로 컴파일했습니다. 예제에서는 포트 13을 사용할 수 없으므로 서버 및 클라이언트 예제의 포트 번호 만 변경했습니다. 서버가 잘 실행되지만 클라이언트가 연결하지 않고 오류가 표시되지 않습니다.간단한 서버/클라이언트 부스트 예제가 작동하지 않습니다.
클라이언트의 입력 데이터는 "127.0.0.1"입니다.
서버 :
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
std::string make_daytime_string()
{
using namespace std; // For time_t, time and ctime;
time_t now = time(0);
return ctime(&now);
}
int main()
{
try
{
boost::asio::io_service io_service;
tcp::endpoint endpoint(tcp::v4(), 8087);
tcp::acceptor acceptor(io_service, endpoint);
for (;;)
{
tcp::iostream stream;
acceptor.accept(*stream.rdbuf());
stream << "test" << make_daytime_string();
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
그리고 클라이언트 :
#include <iostream>
#include <string>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main(int argc, char* argv[])
{
try
{
if (argc != 2)
{
std::cerr << "Usage: daytime_client <host>" << std::endl;
return 1;
}
tcp::iostream s(argv[1], 8087);
std::string line;
std::getline(s, line);
std::cout << line << std::endl;
}
catch (std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
}
return 0;
}
서버와 독립적으로 클라이언트를 사용해 보셨습니까? –