Note that there are some explanatory texts on larger screens.

plurals
  1. PObad characters with asynchrone function in boost asio
    text
    copied!<p>i have a problem with data transfert in boost::asio. with the following code :</p> <p>Server.cpp</p> <pre><code>void Server::accept(void) { Network::ptr connection = Network::create(this-&gt;my_acceptor.get_io_service()); this-&gt;my_acceptor.async_accept(connection-&gt;getSocket(), bind(&amp;Server::endCmd, this, connection, placeholders::error)); } void Server::endCmd(Network::ptr connection, const boost::system::error_code&amp; error) { if (!error) { connection-&gt;Swrite("BIENVENUE"); this-&gt;accept(); } } </code></pre> <p>Network.cpp</p> <pre><code>void Network::Sread(void) { async_read(this-&gt;socket, buffer(this-&gt;rbuffer), bind(&amp;Network::endRead, shared_from_this(), placeholders::error)); } void Network::endRead(const error_code&amp; error) { if (!error) { this-&gt;rcv_msg = this-&gt;rbuffer.c_array(); std::cout &lt;&lt; this-&gt;rcv_msg &lt;&lt; std::endl; this-&gt;Sread(); } } void Network::Swrite(std::string msg) { this-&gt;msg = msg; async_write(this-&gt;socket, buffer(this-&gt;msg, (int)this-&gt;msg.size()), bind(&amp;Network::endWrite, shared_from_this(), placeholders::error)); } void Network::endWrite(const error_code &amp;error) { if (!error) { this-&gt;Sread(); } } tcp::socket&amp; Network::getSocket(void) { return (this-&gt;socket); } Network::ptr Network::create(io_service &amp;ios) { return (ptr(new Network(ios))); } </code></pre> <p>When i send a string like "Hello world" to the server with telnet, he write the following content : <img src="https://i.stack.imgur.com/CaDcd.png" alt="bug with my serveur"></p> <p>Who can tell me why the server is writting many unknow characters ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload