コード例 #1
0
	void on_close(connection_ptr con) {
		m_con = connection_ptr();
		con->stop_heartbeat();

		con->alog().at(log::alevel::DEVEL)<<"client was disconnected sid "<<  con->m_endpoint.m_strSid <<log::endl;

	}
コード例 #2
0
	void on_open(connection_ptr con) {
		m_con = con;

		con->alog().at(log::alevel::DEVEL)<<"Successfully connected sid "<<  con->m_endpoint.m_strSid <<log::endl;
	}
コード例 #3
0
	void on_connect(connection_ptr con) {

		con->alog().at(log::alevel::DEVEL)<<"Connection on_connect"<<  log::endl;
	}
コード例 #4
0
    void on_fail(connection_ptr con) {

		con->alog().at(log::alevel::DEVEL)<<"Connection Connection connected "<<  log::endl;
	}
コード例 #5
0
	// got a new message from server
	void on_message(connection_ptr con, message_ptr msg){
		//https://github.com/LearnBoost/socket.io-spec#Encoding
		/*	0		Disconnect
		1::	Connect
		2::	Heartbeat
		3:: Message
		4:: Json Message
		5:: Event
		6	Ack
		7	Error
		8	noop
		*/
		std::string strm = msg->get_payload();
		char f = strm[0];
		std::string::size_type p = 1;
		for(int i = 0 ; i < 2; i++){
			p = strm.find_first_of(':',p+1);
		}
		std::string data = strm.substr(p+1);
		con->alog().at(log::alevel::DEVEL)<<"revc: "<<  strm <<log::endl;
		con->alog().at(log::alevel::DEVEL)<<"type: "<< f <<" data: "<<  data <<log::endl;
		Json::Reader r;
		Json::Value v;
		switch(f){
		case '0':
			close();
			break;
		case '1':
			on_connect(con);
			break;
		case '2':
			con->send_heartbeat();
			break;
		case '3':
			on_strmessage(data,msg);
			break;
		case '4':
			on_jsonmessage(data,msg);
			/*
			var fe:FlashSocketEvent = new FlashSocketEvent(FlashSocketEvent.MSG_JSON);
			fe.data = JSON.decode(dm.msg);
			dispatchEvent(fe);
			*/
			break;
		case '5':

			if(r.parse(data,v)){
				on_event(v["name"].asString(),v["args"],msg);
			}else{
				con->alog().at(log::alevel::DEVEL)<<"parse json failed error  "<<  data <<log::endl;
			}
			/*
			var m:Object = JSON.decode(dm.msg);
			var e:FlashSocketEvent = new FlashSocketEvent(FlashSocketEvent.EVENT);
			e.data = m;
			dispatchEvent(e);
			*/
			break;
		case '7':
			//on_fail();	
			/*
			var m:Object = JSON.decode(dm.msg);
			var e:FlashSocketEvent = new FlashSocketEvent(FlashSocketEvent.CONNECT_ERROR);
			e.data = dm.msg;
			dispatchEvent(e);
			*/

			break;
		default:
			break;
		}
	}