Esempio n. 1
0
 void on_message(connection_ptr connection,message::data_ptr msg) {
     wscmd::cmd command = wscmd::parse(msg->get_payload());
     
     std::cout << "msg: " << msg->get_payload() << std::endl;
     
     if (command.command == "ack") {
         handle_ack(connection,command);
     } else {
         broadcast_message(msg);
     }
 }
Esempio n. 2
0
 void broadcast_message(message::data_ptr msg) {
     std::string hash = md5_hash_hex(msg->get_payload());
     struct msg& new_msg(m_msgs[hash]);
     
     new_msg.id = m_nextid++;
     new_msg.hash = hash;
     new_msg.size = msg->get_payload().size();
     new_msg.time_sent = boost::posix_time::microsec_clock::local_time();
     new_msg.time = 0;
     
     typename std::set<connection_ptr>::iterator it;
     
     // broadcast to clients        
     for (it = m_connections.begin(); it != m_connections.end(); it++) {
         //(*it)->send(msg->get_payload(),(msg->get_opcode() == frame::opcode::BINARY));
         for (int i = 0; i < 10; i++) {
             (*it)->send(msg);
         }
         
     }
     new_msg.sent = m_connections.size()*10;
     new_msg.acked = 0;
 }