def checkmsg(self): while True: read_fds = [self.sock1, self.sock2] r, w, e = select.select(read_fds, [], [], 0) if not r: break for fd in r: msg, rpc_flag = scop.scop_get_message(fd) player = -1 if fd == self.sock1: player = 1 elif fd == self.sock2: player = 2 print "Received <" + msg + "> from player " + str(player) if player > 0: if msg == "ok": self.ok(player - 1) elif msg == "dropout": self.dropout(player - 1) self.parent.after(40, self.checkmsg)
def checkmsg(self): while True: read_fds = [self.sock1, self.sock2] r, w, e = select.select(read_fds, [], [], 0) if not r: break for fd in r: msg, rpc_flag = scop.scop_get_message(fd) player = -1 if fd == self.sock1: player = 1 elif fd == self.sock2: player = 2 #print "Received <" + msg + "> from player " + str(player) if player > 0: if msg == "a": self.Accelerate(player - 1) elif msg == "d": self.Decelerate(player - 1) elif msg == "l": self.TurnLeft(player - 1) elif msg == "r": self.TurnRight(player - 1) elif msg == "s": self.Pause(player - 1) self.parent.after(40, self.checkmsg)
#!/usr/bin/python # receiver.py - DMI - 29-10-03 import scop, sys sock = scop.scop_open("localhost", "receiver") if sock == None: print "Error on open" sys.exit() while 1: msg, rpc_flag = scop.scop_get_message(sock) print "Received <" + msg + ">" if msg == "quit": break scop.scop_close(sock)
#!/usr/bin/python # multi_listener.cpp - DMI - 7-11-03 # Usage: multi_listener [ <source-one> <source-two> ] # (default sources are "news" and "updates") import scop, sys, select sock = [] for i in range(2): sock.append(scop.scop_open("localhost", "multi_listener")) if len(sys.argv) == 3: scop.scop_listen(sock[0], argv[1]) scop.scop_listen(sock[1], argv[2]) else: scop.scop_listen(sock[0], "news") scop.scop_listen(sock[1], "updates") while 1: read_fds = [sock[0], sock[1]] r, w, e = select.select(read_fds, [], []) for fd in r: msg, rpc_flag = scop.scop_get_message(fd) print "Received <" + msg + "> from ", if fd == sock[1]: print "updates" else: print "news"