def open(self):
        self.usezlib=int(self.get_argument('usezlib',0))

        sessionid=self.get_argument('sessionid',None)
        cdata=self.get_argument('cdata',None)
        self.userdata=None
        if sessionid:
            self.userdata=DecodeCryptSession(sessionid)
            if self.userdata:
                self.userdata['uid']=str(self.userdata['uid'])
        if sessionid and self.userdata is None:
            self.close()
            return

        self.connid=uuid.uuid4().get_hex()
        print self.connid+' connected'
        connection_list[self.connid]=self
        self.last_act_time=time.time()
        self.cip=self.request.remote_ip

        if self.userdata:
            msgbody=DefJsonEncoder.encode(
                {
                    "func":"session.start2",
                    "parm":{
                        "sessionid":None,
                    },
                    "cdata":cdata
                }
            )
            msg=Message(body=msgbody,delivery_mode=2,reply_to=mqserver.back_queue)
            msg.headers={"connid":self.connid,'cip':self.cip,"uid":self.userdata['uid'],
                         'stime':time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(self.userdata.get('time'))),'suuid':self.userdata.get('uuid').hex}
            mqserver.publish(msg)
class RabbitMQServer(tornado.websocket.WebSocketHandler):
    def check_origin(self, origin):
        return True
    last_act_time=0
    def open(self):
        self.usezlib=int(self.get_argument('usezlib',0))

        sessionid=self.get_argument('sessionid',None)
        cdata=self.get_argument('cdata',None)
        self.userdata=None
        if sessionid:
            self.userdata=DecodeCryptSession(sessionid)
            if self.userdata:
                self.userdata['uid']=str(self.userdata['uid'])
        if sessionid and self.userdata is None:
            self.close()
            return

        self.connid=uuid.uuid4().get_hex()
        print self.connid+' connected'
        connection_list[self.connid]=self
        self.last_act_time=time.time()
        self.cip=self.request.remote_ip

        if self.userdata:
            msgbody=DefJsonEncoder.encode(
                {
                    "func":"session.start2",
                    "parm":{
                        "sessionid":None,
                    },
                    "cdata":cdata
                }
            )
            msg=Message(body=msgbody,delivery_mode=2,reply_to=mqserver.back_queue)
            msg.headers={"connid":self.connid,'cip':self.cip,"uid":self.userdata['uid'],
                         'stime':time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(self.userdata.get('time'))),'suuid':self.userdata.get('uuid').hex}
            mqserver.publish(msg)
    def on_message(self, message):
        try:
            if self.usezlib:
                message=zlib.decompress(message)
        except Exception,e:
            pass
        msg=Message(body=message,delivery_mode=2,reply_to=mqserver.back_queue)
        msg.headers={"connid":self.connid,'cip':self.cip}
        if self.userdata:
            msg.headers['uid']=self.userdata['uid']
        mqserver.publish(msg)
        self.last_act_time=time.time()