Beispiel #1
0
    def dataReceived(self, data):
        if self._ignore_incoming:
            return

        self._data += data

        while self._data:
            # handle packet
            if self.established:

                # packet head
                if self._cur_packet_length == None:
                    if len(self._data) >= S_PACKET_HEAD.size:
                        _type, length = S_PACKET_HEAD.unpack_from(self._data)
                        self._cur_packet_length = S_PACKET_HEAD.size + length

                    # not enough data for packet head
                    else: break

                # packet data
                elif len(self._data) >= self._cur_packet_length:
                    self.packetReceived(binarypack.unpack(self._data))
                    self._data = self._data[self._cur_packet_length:]
                    self._cur_packet_length = None

                # not enough data for packet
                else: break

            # handle handshake
            elif len(self._data) >= len(protocol_handshake):
                self._checkVersion(self._data[:len(protocol_handshake)])
                self._data = self._data[len(protocol_handshake):]

            # not enough data for handshake
            else: break
Beispiel #2
0
    def dataReceived(self, data):
        if self._ignore_incoming:
            return

        self._data += data

        while self._data:
            # handle packet
            if self.established:

                # packet head
                if self._cur_packet_length == None:
                    if len(self._data) >= S_PACKET_HEAD.size:
                        _type, length = S_PACKET_HEAD.unpack_from(self._data)
                        self._cur_packet_length = S_PACKET_HEAD.size + length

                    # not enough data for packet head
                    else:
                        break

                # packet data
                elif len(self._data) >= self._cur_packet_length:
                    self.packetReceived(binarypack.unpack(self._data))
                    self._data = self._data[self._cur_packet_length:]
                    self._cur_packet_length = None

                # not enough data for packet
                else:
                    break

            # handle handshake
            elif len(self._data) >= len(protocol_handshake):
                self._checkVersion(self._data[:len(protocol_handshake)])
                self._data = self._data[len(protocol_handshake):]

            # not enough data for handshake
            else:
                break
 def check_pack_unpack(packet):
     assert packet.type != -1 
     packed = binarypack.pack(packet)
     assert binarypack.unpack(packed) == packet
Beispiel #4
0
 def check_pack_unpack(packet):
     assert packet.type != -1
     packed = binarypack.pack(packet)
     assert binarypack.unpack(packed) == packet