示例#1
0
    def handle(self):
        client_proto = proto.determine(self.rfile)
        if client_proto not in ['local']:
            print("Invalid protocol")
            return

        while True:
            header = local_proto.Header.from_stream(self.rfile)
            if header is None:
                print("Client disconnected")
                return
            print("Received: {}, {}".format(header.pkt_type, header.payload_len))
            pkt_data = self.rfile.read(header.payload_len)

            local_proto.handle(header, pkt_data, self.wfile)
示例#2
0
def twoway(sock, initiator=True):
    if initiator:
        # TODO: send proto, intro packet
        pass
    else:
        # Read proto, intro packet
        other_proto = proto.determine(self.rfile)
        if client_proto not in ['internode']:
            return

    while True:
        # TODO: data queue for writing?
        (rready, wready, xready) = select.select([sock], [], [], 0)
        if len(rready) > 0:
            # TODO: Read one packet
            pass