皆私は本当にあなたの助けが必要です。私はboost::asio
を学んだし、私は日のために対処することができない2つの問題...ここ簡単な機能を持つboost :: asioサーバー
は自分自身で行う簡単なエコーサーバの例である:
int main(
{
// crate a server, binding it and listening connections
// acceptor server;
//socket client
server.async_accept(client, boost::bind(accept_handle, _1, &server, &client));
io_service.run();
return 0;
}
void accept_handle(const boost::system::error_code& eCode, boost::asio::ip::tcp::acceptor* server, boost::asio::ip::tcp::socket* client)
{
char data[43];
client->async_read_some(boost::asio::buffer(data, 20), boost::bind(read_handle, _1, _2, server, client));
}
void read_handle(const boost::system::error_code& eCode, size_t bytes)
{
char data_buf[20] = "hello";
client->async_write_some(boost::buufer(data, 5), boost::bind(write_handle, _1, _2, server, client));
}
void write_accept(const boost::system::error_code& eCode, size_t bytes)
{
boost::asio::ip::tcp::socket newConnection(server->get_ioservice)); // taking he io_service of the server
server->async_accept(newConnection, boost::bind(accept_handle, _1, server, client));
}
問題がサーバであるが1つのクライアントを受け入れ、それが他の保留中のクライアントを許可していません...どこ私が間違っているのここ
注:いずれかが存在する場合、私はメモ帳で構文エラーのためにとても残念にこのコードを書きました。
事前にお手数をおかけしますようお願いいたします。それはaccept_handle
機能でasync_accept
を呼び出すではないので
async_acceptは1つの接続を受け入れます。 'accept_handle'関数で再度呼び出す必要があります。 –
[複数のクライアントを同時に処理できるブーストサーバーを作成するにはどうすればよいですか?](https://stackoverflow.com/questions/31579362/how-do-i-create-a-boost-server-that- can-handle-multiple-clients-at-once) –
リチャード・ホッジスは、サーバーがクライアントから読み込んでいるときに別の接続を受け入れるためにaccept_handleを呼び出す必要があるが、なぜwrite_handleからasync_handleを呼び出すのが間違っているのか? –