コード例 #1
0
    def process_buffer(self):
        """
        Attempt to parse the packet from the buffer.

        If a complete packet exists in the buffer it is removed and
        the server packet_read callback is invoked.

        Returns True iff a packet was processed.
        """
        if not self.packet_size:
            self.packet_size = Packet.read_length(self.buffer_in)
            if self.packet_size:
                print "Reading packet with length %s" % self.packet_size

        if self.packet_size and len(self.buffer_in) >= self.packet_size:
            # remove from buffer
            raw_packet = self.buffer_in[0:self.packet_size]
            self.buffer_in = self.buffer_in[self.packet_size:]
            self.packet_size = None
            # callback
            self.server.packet_read(self, raw_packet)

            return True
コード例 #2
0
    def process_buffer(self):
        """
        Attempt to parse the packet from the buffer.

        If a complete packet exists in the buffer it is removed and
        the server packet_read callback is invoked.

        Returns True iff a packet was processed.
        """
        if not self.packet_size:
            self.packet_size = Packet.read_length(self.buffer_in)
            if self.packet_size:
                print "Reading packet with length %s" % self.packet_size

        if self.packet_size and len(self.buffer_in) >= self.packet_size:
            # remove from buffer
            raw_packet = self.buffer_in[0:self.packet_size]
            self.buffer_in = self.buffer_in[self.packet_size:]
            self.packet_size = None
            # callback
            self.server.packet_read(self, raw_packet)

            return True