def data_received(self, data): """ incoming data are ready """ # compute all packets while (len(data) > 0): packet = Packet(data) size = packet.getVarint() offset = packet.getVarintSize() packet = Packet(data[offset:offset+size]) # compute the packet self.protocol.Receive(packet) # remove the packet data = data[offset+size:]