私のサーバーは、クライアントが接続するまで正常に動作し、クライアントにメッセージを送信しようとします。これは、クライアントにメッセージを送信するための関数です。このコードを実行すると、エラーでクラッシュします
SERVER.exe の 0x6351117C (msvcr110d.dll) で未処理の例外: 0xC0000005: アクセス違反の読み取り場所 0x00000002。
template <typename T, typename Handler>
void AsyncWrite(const T& t, Handler handler)
{
std::ostringstream archiveStream;
boost::archive::text_oarchive archive(archiveStream);
archive << t;
outboundData = archiveStream.str();
std::ostringstream headerStream;
headerStream << std::setw(headerLength) << std::hex << outboundData.size();
if (!headerStream || headerStream.str().size() != headerLength)
{
boost::system::error_code error(boost::asio::error::invalid_argument);
socket.get_io_service().post(boost::bind(handler, error));
return;
}
outboundHeader = headerStream.str();
std::vector<boost::asio::const_buffer> buffers;
buffers.push_back(boost::asio::buffer(outboundHeader));
buffers.push_back(boost::asio::buffer(outboundData));
boost::asio::async_write(socket, buffers, handler);
}
編集:それが重要かどうかはわかりませんが、この例に従っています
http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/example/cpp03/serialization/connection.hpp