Ejemplo n.º 1
0
    def on_message(self, msg):
        parts = msg.split(',', 2)
        op, chan = parts[0], parts[1]

        #if chan not in self.channels:
        #    return

        if chan in self.endpoints:
            session = self.endpoints[chan]

            if op == 'uns':
                del self.endpoints[chan]
                session._close()
            elif op == 'msg':
                session.on_message(parts[2])
        else:
            if op == 'sub':
                session = ChannelSession(self.objClass,
                                         self.session.server,
                                         self,
                                         chan)
                session.set_handler(self.handler)
                session.verify_state()

                self.endpoints[chan] = session
Ejemplo n.º 2
0
    def on_message(self, msg):
        self.last_rcv = time.time()
        if msg == 'h':
            return

        parts = msg.split(',', 2)
        op, chan = parts[0], parts[1]

        if chan not in self.channels:
            return

        if chan in self.endpoints:
            session = self.endpoints[chan]

            if op == 'uns':
                del self.endpoints[chan]
                session._close()
            elif op == 'msg':
                session.on_message(parts[2])
        else:
            if op == 'sub':
                session = ChannelSession(self.channels[chan],
                                         self.session.server, self, chan)
                session.set_handler(self.handler)
                session.verify_state()

                self.endpoints[chan] = session
Ejemplo n.º 3
0
    def on_message(self, message):
        parts = message.split(',', 2)
        operation, channel = parts[0], parts[1]
        channel_parts = parts[1].split(':')

        if channel_parts[0] not in self.channels:
            return

        if channel in self.endpoints:
            session = self.endpoints[channel]

            if operation == 'uns':
                del self.endpoints[channel]
                session._close()
            elif operation == 'msg':
                session.on_message(parts[2])
        else:
            if operation == 'sub':
                session = MultiplexChannelSession(self.channels[channel],
                                                  self.session.server,
                                                  self,
                                                  channel)
                session.set_handler(self.handler)
                session.verify_state()
                self.endpoints[channel] = session
Ejemplo n.º 4
0
    def on_message(self, msg):
        parts = msg.split(',', 2)
        op, chan = parts[0], parts[1]

        if chan not in self.channels:
            if self.defaultConnectionClass == None:
                return
            else:
                self.channels[chan] = self.defaultConnectionClass

        if chan in self.endpoints:
            session = self.endpoints[chan]

            if op == 'uns':
                del self.endpoints[chan]
                session._close()
            elif op == 'msg':
                session.on_message(parts[2])
        else:
            if op == 'sub':
                session = ChannelSession(self.channels[chan],
                                         self.session.server,
                                         self,
                                         chan)
                session.set_handler(self.handler)
                session.verify_state()

                self.endpoints[chan] = session

        def on_close(self):
            for ep in self.endpoints:
                ep._close()
Ejemplo n.º 5
0
    def on_message(self, msg):

        print "\ninside MultiplexConnection on_message function"

        print " pre parts msg : ", msg
        parts = msg.split(',', 2)
        print "post Parts  msg : ", parts
        op, chan = parts[0], parts[1]

        print 'op : ', op
        print 'chan : ', chan

        print "current channels : ", self.channels
        print 'current endpoints : ', self.endpoints

        if chan not in self.channels:
            print ' chan not in self.channels'
            return

        if chan in self.endpoints:
            print 'chan in self.endpoints'
            session = self.endpoints[chan]
            print 'session : ', session

            if op == 'uns':
                print 'op==uns'
                print 'current self.endpoints : ', self.endpoints
                del self.endpoints[chan]
                print 'updates self.endpoints : ', self.endpoints
                print 'invoking session._close()'
                session._close()
                print 'session._close invokes sucsessfully'
            elif op == 'msg':
                print 'op==msg'
                print 'current self.endpoints : ', self.endpoints
                print "current parts : ", parts
                print 'invoking session.on_message(parts[2])'
                session.on_message(parts[2])
                print 'session.on_message(parts[2]) invokes sucsessfully'
        else:
            print 'chan not in self.endpoints'
            if op == 'sub':
                print 'op==sub'
                print 'self.channels[chan] : ', self.channels[chan]
                print 'self.session.server : ', self.session.server
                print 'chan : ', chan
                print 'invokeing session=ChannelSession'
                session = ChannelSession(self.channels[chan],
                                         self.session.server, self, chan)
                print 'invoked session=channelSession successfully'
                print 'session : ', session
                print 'setting session.set_handler(self.handler)'
                session.set_handler(self.handler)
                print 'session.set_handler(self.handler) invoked successfully'
                print 'invoking session.verify_state()'
                session.verify_state()
                print 'session.verify_state invoked successfully'

                self.endpoints[chan] = session
        print 'returning from MultiplexConnection on_message'
Ejemplo n.º 6
0
    def on_message(self, msg):
        """ This method is called whenever a client sends a message, which is recieved by a MultiplexConnection as an entrypoint.
        
        Args:
            msg (str): A string that should be in JSON syntax. It must contains the following keys::
            msg = {
                "channel": "The name of the Dyanmic Chanel(DynamicConnection) to be addressed."
                "action": "One of : UNS, MSG, or JOIN in this example."
                "data": "The data that will be transmitted to the channel"
            }
        Returns:
            None
        """
        message_json_object = json.loads(msg)
        '''# This creates the channel if it is not already created.
        '''
        if message_json_object['channel'] not in self.channels:
            self.channels[message_json_object['channel']] = self._channel_factory(message_json_object['channel'])
            if self.channels[message_json_object['channel']] is None:
                self.channels.pop(message_json_object['channel'])
                self.close()
        '''# Here the channel session is added to the client's endpoints if it isn't already,
        and the message is handled.
        '''
        if message_json_object['channel'] in self.endpoints:
            session = self.endpoints[message_json_object['channel']]

            if message_json_object["action"] == 'UNS':
                del self.endpoints[message_json_object['channel']]
                session._close()
            elif message_json_object["action"] == 'MSG':
                session.on_message(message_json_object["data"])
        else:
            if message_json_object["action"] == 'JOIN':
                session = ChannelSession(self.channels[message_json_object['channel']],
                                        self.session.server,
                                        self,
                                        message_json_object['channel'])
                '''# Pass the handler to the newly created session. This
                enables the channel to use the request information provided by the handler
                such as the request cookies.
                '''
                session.set_handler(self.handler)
                session.verify_state()

                self.endpoints[message_json_object['channel']] = session
Ejemplo n.º 7
0
    def on_message(self, msg):
        parts = msg.split(",", 2)
        op, chan = parts[0], parts[1]

        if chan not in self.channels:
            return

        if chan in self.endpoints:
            session = self.endpoints[chan]

            if op == "uns":
                del self.endpoints[chan]
                session._close()
            elif op == "msg":
                session.on_message(parts[2])
        else:
            if op == "sub":
                session = ChannelSession(self.channels[chan], self.session.server, self, chan)
                session.set_handler(self.handler)
                session.verify_state()

                self.endpoints[chan] = session
Ejemplo n.º 8
0
    def on_message(self, msg):
        
        print "\ninside MultiplexConnection on_message function"
	
    	print " pre parts msg : ",msg
    	parts = msg.split(',', 2)
    	print "post Parts  msg : ",parts
        op, chan = parts[0], parts[1]

        print 'op : ',op
        print 'chan : ',chan

        print "current channels : ",self.channels
        print 'current endpoints : ',self.endpoints

        if chan not in self.channels:
            print ' chan not in self.channels'
            return

        if chan in self.endpoints:
            print 'chan in self.endpoints'
            session = self.endpoints[chan]
            print 'session : ',session

            if op == 'uns':
                print 'op==uns'
                print 'current self.endpoints : ',self.endpoints
                del self.endpoints[chan]
                print 'updates self.endpoints : ',self.endpoints
                print 'invoking session._close()'
                session._close()
                print 'session._close invokes sucsessfully'
            elif op == 'msg':
                print 'op==msg'
                print 'current self.endpoints : ',self.endpoints
                print "current parts : ",parts
                print 'invoking session.on_message(parts[2])'
                session.on_message(parts[2])
                print 'session.on_message(parts[2]) invokes sucsessfully'
        else:
            print 'chan not in self.endpoints'
            if op == 'sub':
                print 'op==sub'
                print 'self.channels[chan] : ',self.channels[chan]
                print 'self.session.server : ',self.session.server
                print 'chan : ',chan
                print 'invokeing session=ChannelSession'
                session = ChannelSession(self.channels[chan],
                                         self.session.server,
                                         self,
                                         chan)
                print 'invoked session=channelSession successfully'
                print 'session : ',session
                print 'setting session.set_handler(self.handler)'
                session.set_handler(self.handler)
                print 'session.set_handler(self.handler) invoked successfully'
                print 'invoking session.verify_state()'
                session.verify_state()
                print 'session.verify_state invoked successfully'

                self.endpoints[chan] = session
        print 'returning from MultiplexConnection on_message'