Ejemplo n.º 1
0
    void client_impl::on_handshake(message::ptr const& message)
    {
        if(message && message->get_flag() == message::flag_object)
        {
            const object_message* obj_ptr =static_cast<object_message*>(message.get());
            const map<string,message::ptr>* values = &(obj_ptr->get_map());
            auto it = values->find("sid");
            if (it!= values->end()) {
                m_sid = static_pointer_cast<string_message>(it->second)->get_string();
            }
            else
            {
                goto failed;
            }
            it = values->find("pingInterval");
            if (it!= values->end()&&it->second->get_flag() == message::flag_integer) {
                m_ping_interval = (unsigned)static_pointer_cast<int_message>(it->second)->get_int();
            }
            else
            {
                m_ping_interval = 25000;
            }
            it = values->find("pingTimeout");

            if (it!=values->end()&&it->second->get_flag() == message::flag_integer) {
                m_ping_timeout = (unsigned) static_pointer_cast<int_message>(it->second)->get_int();
            }
            else
            {
                m_ping_timeout = 60000;
            }

            m_ping_timer.reset(new boost::asio::deadline_timer(m_client.get_io_service()));
            boost::system::error_code ec;
            m_ping_timer->expires_from_now(milliseconds(m_ping_interval), ec);
            if(ec)LOG("ec:"<<ec.message()<<endl);
            m_ping_timer->async_wait(lib::bind(&client_impl::ping,this,lib::placeholders::_1));
            LOG("On handshake,sid:"<<m_sid<<",ping interval:"<<m_ping_interval<<",ping timeout"<<m_ping_timeout<<endl);
            return;
        }
failed:
        //just close it.
        m_client.get_io_service().dispatch(lib::bind(&client_impl::close_impl, this,close::status::policy_violation,"Handshake error"));
    }
Ejemplo n.º 2
0
const boost::python::object messageW::get_pyo(const message::ptr& ptr){
	boost::python::list list;
	boost::python::dict dict;
	switch(ptr->get_flag()) {
	case sio::message::flag_null:
		return boost::python::object();
		break;
	case sio::message::flag_boolean:
		return boost::python::object(ptr->get_bool());
		break;
	case sio::message::flag_integer:
		return boost::python::object(ptr->get_int());
		break;
	case sio::message::flag_double:
		return boost::python::object(ptr->get_double());
		break;
	case sio::message::flag_string:
		return boost::python::object(ptr->get_string());
		break;
	case sio::message::flag_binary:
		return boost::python::object("binary(string)");
		break;
	case sio::message::flag_array:
		for(auto&& e:ptr->get_vector()){
		 list.append(get_pyo(e));
		}
		return list;
		break;
	case sio::message::flag_object:
		for(auto&& e:ptr->get_map()){
			dict[e.first]=get_pyo(e.second);
		}
		return dict;
		break;
	}
	return boost::python::object();
}