私はHTTPS
のリクエストを受信し、3つの応答で回答する必要があるサーバーを開発中です。最初の2つは何らかの回線ACKであり、最後の1つは要求された情報を含んでいます。ブーストアシオからブラウザに複数の応答を送信
私はクライアントとして自分のウェブブラウザ(クロム)を使用しています。私が欲しいのは次のとおりです。
- ブラウザ(クライアント)がサーバーに要求を送信します。
- サーバーが最初のACK(htmlページ)を送信し、ブラウザがそれを表示します。
- 2秒後、サーバーは別のACK(別のHTMLページ)を送信し、ブラウザはそれを表示します。
- さらに2秒後、サーバーは要求された情報(別のhtmlページ)を送信し、ブラウザーはそれを表示します。
問題は、あってもHTTPS
ヘッダにkeep-alive
にConnection
を設定、それを読んだ後、ソケットを閉じていると思わ、ブラウザは最初のACKを受信することです。
HTTPS
の回答をウェブブラウザで待つ方法はありますか?
ソース
これは請願が行われたときに、サーバーで実行される非同期メソッドが含まれています。
void handle_handshake(const boost::system::error_code& error)
{
if (!error)
{
boost::asio::async_read_until(socket_, request_, "\r\n\r\n",
boost::bind(&session::handle_read, this,
boost::asio::placeholders::error));
}
else
{
std::cout << "ERROR, deleting. " << __FILE__ << ":" << __LINE__ << std::endl;
delete this;
}
}
void handle_read(const boost::system::error_code& err)
{
if (!err)
{
std::string s = "some_response";
// First write. This write is received by the browser without problems.
boost::asio::async_write(socket_,
boost::asio::buffer(response),
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
}
else
{
std::cout << "Error: " << err << "\n";
}
}
void handle_write(const boost::system::error_code& error)
{
if (!error)
{
if(n++ <= 2)
{
// Second and third writes.
// These ones are not read by the browser.
if(n == 1)
{
std::string s = "some_response2";
boost::asio::async_write(socket_,
boost::asio::buffer(response),
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
}
else if (n==2)
{
std::string s = "some_response3";
boost::asio::async_write(socket_,
boost::asio::buffer(response),
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
}
sleep(1);
}
}
else
{
std::cout << "ERROR, deleting: " << __FILE__ << ":" << __LINE__ << std::endl;
delete this;
}
}
コードスニペットを表示できますか? –