def handle_read(self):
        if len(self.data) < self.preheader_size:
            self.data += self.recv(self.preheader_size)
            if not self.data:
                return
            preheader = struct.unpack(self.preheader_fmt, self.data)
            self.msg_length = preheader[1]
        else:
            self.data += self.recv(self.msg_length)

        print self.msg_length
        print self.data.encode("hex")

        if len(self.data) >= self.msg_length:
            mt_packet = None
            mt_messages = deque()
            try:
                mt_packet = parse_mt_directip_packet(self.data, mt_messages)
            except:
                print 'MT Handler: Invalid message'
                sys.stdout.flush()

            imei = mt_packet[0][1]

            print 'Attempting to forward message for imei: {}'.format(imei)

            if forward_address.has_key(imei):
                self.client = ConditionalSBDForwardClient(
                    self, forward_address[imei][0], forward_address[imei][1])
                self.client.send(self.data)
                self.data = ''
            else:
                print 'No forwarding set up for imei: {}'.format(imei)
                self.close()
    def handle_read(self):
        if len(self.data) < self.preheader_size:
            self.data += self.recv(self.preheader_size)
            if not self.data:
                return
            preheader = struct.unpack(self.preheader_fmt, self.data)
            self.msg_length = preheader[1]
        else:
            self.data += self.recv(self.msg_length)
        
        print self.msg_length
        print self.data.encode("hex")
            
        if len(self.data) >= self.msg_length:
            mt_packet = None
            mt_messages = deque()
            try: 
                mt_packet = parse_mt_directip_packet(self.data, mt_messages)
            except:
                print 'MT Handler: Invalid message'
                sys.stdout.flush()
                
            imei = mt_packet[0][1]
                
            print 'Attempting to forward message for imei: {}' .format(imei)

            if forward_address.has_key(imei):
                self.client = ConditionalSBDForwardClient(self, forward_address[imei][0], forward_address[imei][1])
                self.client.send(self.data)
                self.data = ''
            else:
                print 'No forwarding set up for imei: {}'.format(imei)
                self.close()
Beispiel #3
0
    def handle_read(self):
        global mt_messages

        if len(self.data) < self.preheader_size:
            self.data += self.recv(self.preheader_size)
            preheader = struct.unpack(self.preheader_fmt, self.data)
            self.msg_length = preheader[1]
        else:
            self.data += self.recv(self.msg_length)

        print self.msg_length
        print self.data.encode("hex")

        if len(self.data) >= self.msg_length:
            mt_packet = None
            try:
                mt_packet = parse_mt_directip_packet(self.data, mt_messages)
            except:
                print 'MT Handler: Invalid message'
            # response message
            self.send(assemble_mt_directip_response(mt_packet, mt_messages))
            self.handle_close()
Beispiel #4
0
    def handle_read(self):
        global mt_messages

        if len(self.data) < self.preheader_size:
            self.data += self.recv(self.preheader_size)
            preheader = struct.unpack(self.preheader_fmt, self.data)
            self.msg_length = preheader[1]
        else:
            self.data += self.recv(self.msg_length)
        
        print self.msg_length
        print self.data.encode("hex")
            
        if len(self.data) >= self.msg_length:
            mt_packet = None
            try: 
                mt_packet = parse_mt_directip_packet(self.data, mt_messages)
            except:
                print 'MT Handler: Invalid message'
            # response message
            self.send(assemble_mt_directip_response(mt_packet, mt_messages))
            self.handle_close()