Beispiel #1
0
    def on_frame_header(self, frame):
        _header = ObjectDict()
        header = self._socket.recv(FRAME.DATA_LENGTH) # 先获取ipc数据库
        if not header:
            return

        data_length = struct.unpack(b'!Q', header)[0]
        _header.data_length = data_length

        frame.update(_header)
Beispiel #2
0
    def recv_frame_data(self):
        frame = ObjectDict()
        self._on_frame_header(self.recv_bytes(2), frame)


        if frame.payload_len < 126:
            pass
        elif frame.payload_len == 126:
            frame.payload_len = struct.unpack(b'!H', self.recv_bytes(2))[0]
            # frame.payload_len = sum([ _d & (0xFF << (base * 8)) for base in range(2)])
        elif frame.payload_len == 127:
            frame.payload_len  = struct.unpack(b'!Q', self.recv_bytes(8))[0]
            # frame.payload_len = sum([ _d & (0xFF << (base * 8)) for base in range(4)])

        if frame.mask:
            self._on_frame_mask_key(self.recv_bytes(4), frame)
    
        self._on_frame_data(self.recv_bytes(frame.payload_len), frame)

        return frame