を送るASIOファイルには、HTTP経由での.pngファイルを応答サーバーがあります:ブースト::
#include "server.h"
string Server::header(int contentLength)
{
string h =
"HTTP/1.1 200 OK\n"
"Content-Length: " + boost::lexical_cast<string>(contentLength) + "\n"
"Content-Type: image/png;\n"
"Connection: close\n"
"\n";
return h;
}
string Server::readMap(const string &filename)
{
ifstream file (filename.c_str(), ios::in|ios::binary);
string reply;
char buf[512];
while (file.read(buf, sizeof(buf)).gcount() > 0)
reply.append(buf, file.gcount());
return reply;
}
void Server::run(const string &filename, int port)
{
string data = readMap(filename);
try
{
boost::asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), port));
for (;;)
{
tcp::socket socket(io_service);
acceptor.accept(socket);
boost::asio::write(socket, boost::asio::buffer(header(data.size())));
boost::asio::write(socket, boost::asio::buffer(data));
}
}
catch (std::exception& e)
{
cerr << "exception: " << e.what() << endl;
}
}
エラーが発生するたびに:
例外:ピアによって接続がリセットさ
ブラウザで画像の一部を見ることができますが、画像がほぼ完成していることもありますが、エラーが発生することはありません。
私はwgetを使用している場合は、それはそれを修正する方法を
wget http://localhost:8089
--2012-03-07 12:07:19-- http://localhost:8089/
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:8089... connected.
HTTP request sent, awaiting response... 200 OK
Length: 760032 (742K) [image/png]
Saving to: `index.html'
62% [========================================================> ] 475,136 --.-K/s in 0.002s
2012-03-07 12:07:19 (287 MB/s) - Read error at byte 475136/760032 (Connection reset by peer). Retrying.
--2012-03-07 12:07:20-- (try: 2) http://localhost:8089/
Connecting to localhost|127.0.0.1|:8089... connected.
HTTP request sent, awaiting response... 200 OK
Length: 760032 (742K) [image/png]
Saving to: `index.html'
73% [==================================================================> ] 557,056 --.-K/s in 0.001s
... many failes and finally
--2012-03-07 12:09:01-- (try: 9) http://localhost:8089/
Connecting to localhost|127.0.0.1|:8089... connected.
HTTP request sent, awaiting response... 200 OK
Length: 760032 (742K) [image/png]
Saving to: `index.html'
100%[===========================================================================================>] 760,032 --.-K/s in 0.001s
のように任意のアイデアに見えますか?
ソースと質問を編集しました。何も助けられませんでした( – spe
私はこれを引き起こす可能性は全く考えていませんでしたが、回答を開始する前にリクエストを待たずに何かをする必要があります HTTPプロトコルの回線解析を少なくとも_ それ以外は、間違った行終了(HTTPは\ r \ nが期待されます)を除いて、間違っていることは間違いありませんが、私はそれがあなたの原因ではないかと疑います。 – Rawler
あなたは大丈夫でした!おそらく、少なくともHTTPプロトコルのライン解析を行い、ダブル改行文字を受け取るまで待つべきでしょう。 – spe