0
試圖通過一個連接來發送多個請求:爲什麼ASIO同步寫入newtork無法第二次發送數據?
int count = boost::asio::write(socket, request); // this will result in normal count2
int count2 = boost::asio::write(socket, request); // this one gives zero
然而CONT2等於零,意味着ID不發送數據..何來修復它
添加更多的代碼獲得更好的視野:
boost::asio::io_service io_service;
boost::asio::streambuf lastResponse;
// Get a list of endpoints corresponding to the server name.
tcp::resolver resolver(io_service);
char *host = "somewebsie.coom";
char *requestPath = "/somequery";
tcp::resolver::query query(host, "http");
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
// Try each endpoint until we successfully establish a connection.
tcp::socket socket(io_service);
boost::asio::socket_base::keep_alive option(true);
boost::asio::socket_base::non_blocking_io option2(true);
boost::asio::socket_base::non_blocking_io command(true);
double startTime,endTime;
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << "GET "<< requestPath <<" HTTP/1.1\r\nHost: "<<host <<":80\r\n\r\n";
boost::asio::connect(socket, endpoint_iterator);
socket.set_option(option);
socket.io_control(command);
startTime = getRealTime();
// Form the request. We specify the "Connection: close" header so that the
// server will close the socket after transmitting the response. This will
// allow us to treat all data up until the EOF as the content.
int count2 = boost::asio::write(socket, request);
count2 = boost::asio::write(socket, request);
bool isopen = socket.is_open(); // return true...
真的!經過四年的C#很難回到C++ :) – 2014-10-30 12:20:17