C++: when a message is sent using boost::asio::async_write to client, I receive repeats of the same message as the client -


this code using send string message client. problem, think, has buffer.

void client::send_message(std::string message) { message = message + "\n"; std::ostream sending(&_out_buffer); sending << message; boost::asio::async_write(this->_socket, this->_out_buffer,         boost::bind(&client::send_callback, this,                 boost::asio::placeholders::error,                 boost::asio::placeholders::bytes_transferred));  debugger( "--> message send " + this->_client_name + " : " + message ); 

}

the problem, when send sequence of messages so:

//send data client     client->send_message("connected " + boost::lexical_cast<std::string>(number_of_cells));       //send cells     std::set<std::string> cells = it->second->get_names_of_all_non_empty_cells();     std::set<std::string>::iterator cell = cells.begin();     std::set<std::string>::iterator end = cells.end();     for(; cell != end; cell++) {         client->send_message("cell " + *cell + " " + it->second->get_cell_contents(*cell));     } 

i on client side:

connected 2

connected 2

cell a1 testcontent

connected 2

cell a1 testcontent

cell b4 anothertest

when drop loop in sending code, sends "connected 2" message 1 time. thinking has buffer not being cleared or loaded quickly. unsure though. there way handle situation? occurs when send lot of messages in block of code.

thanks!

edit:

i found workaround, though doesn't fix problem. instead of calling method "send_message" repeatedly, pulled 1 large string , sent it. new code:

//send data client     std::string message = "connected " + boost::lexical_cast<std::string>(number_of_cells) + "\n";       //send cells     std::set<std::string> cells = it->second->get_names_of_all_non_empty_cells();     std::set<std::string>::iterator cell = cells.begin();     std::set<std::string>::iterator end = cells.end();     for(; cell != end; cell++) {         message += "cell " + *cell + " " + it->second->get_cell_contents(*cell) +"\n";     }      client->send_message(message); 


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -