def listen(self, host): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, SERVICE_PORT)) port = Port(sock) port.write(self.subs) while True: res = port.read() if res: self.queue.put(res)
class Source(object): def __init__(self, host): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, SERVICE_PORT)) self.port = Port(sock) def sendall(self, list): for item in list: self.port.write(item) def send(self, item): self.port.write(item)
class Agent(object): def __init__(self, addr): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(addr) self.port = Port(sock) def list(self): self.port.write("?") return json.loads(self.port.read()) def fetch(self, want="*"): if want == "*": req = "*" else: req = json.dumps(want) self.port.write(req) return json.loads(self.port.read())