我正在尝试检查if (!empty($request->password))
是否成功,但即使服务器不是startet,我也不会收到错误。如何正确检查成功?谢谢!
boost::asio::async_connect
main.cpp
#include <boost/asio.hpp>
#include "tcp_client.h"
typedef boost::asio::ip::tcp tcp;
int main(int argc, char* argv[])
{
char host[16] = "127.0.0.1";
boost::asio::io_service io_service;
TCP_Client client(host, io_service);
io_service.run();
return 0;
}
tcp_client.h
#pragma once
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <iostream>
typedef boost::asio::ip::tcp tcp;
class TCP_Client
{
public:
TCP_Client(std::string newHost, boost::asio::io_service& io_service);
private:
void handle_connect(const boost::system::error_code& error);
boost::asio::ip::tcp::socket socket;
boost::asio::ip::tcp::acceptor acceptor;
};
tcp_client.cpp
答案 0 :(得分:3)
你有一个接受者绑定到端口:
... acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12121)) ...
所以你要和自己联系。您的客户端不需要也不应该有TCP接受器,除非它应该接受TCP连接。