diff options
author | Guido van Rossum <guido@python.org> | 1992-12-21 14:32:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-12-21 14:32:55 (GMT) |
commit | b637221d93927b6e1cdcee51d67229b6f6b5bc06 (patch) | |
tree | a26a6913b97cd58db9e1e13bda5793d2f3bd461f /Demo | |
parent | da164d2bffb7bf30c93d016a5edc05c6ab498160 (diff) | |
download | cpython-b637221d93927b6e1cdcee51d67229b6f6b5bc06.zip cpython-b637221d93927b6e1cdcee51d67229b6f6b5bc06.tar.gz cpython-b637221d93927b6e1cdcee51d67229b6f6b5bc06.tar.bz2 |
Full broadcast support
Diffstat (limited to 'Demo')
-rw-r--r-- | Demo/rpc/rnusersclient.py | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/Demo/rpc/rnusersclient.py b/Demo/rpc/rnusersclient.py index ed81081..4d540f8 100644 --- a/Demo/rpc/rnusersclient.py +++ b/Demo/rpc/rnusersclient.py @@ -1,7 +1,7 @@ # Remote nusers client interface import rpc -from rpc import Packer, Unpacker, TCPClient, UDPClient +from rpc import Packer, Unpacker, UDPClient, BroadcastUDPClient class RnusersPacker(Packer): @@ -34,48 +34,65 @@ class RnusersUnpacker(Unpacker): return self.unpack_array(self.unpack_utmpidle) -class RnusersClient(UDPClient): +class PartialRnusersClient: def addpackers(self): self.packer = RnusersPacker().init() self.unpacker = RnusersUnpacker().init('') - def init(self, host): - return UDPClient.init(self, host, 100002, 2) - def Num(self): - self.start_call(1) - self.do_call() - n = self.unpacker.unpack_int() - self.end_call() - return n + return self.make_call(1, None, None, self.unpacker.unpack_int) def Names(self): - self.start_call(2) - self.do_call() - list = self.unpacker.unpack_utmpidlearr() - self.end_call() - return list + return self.make_call(2, None, \ + None, self.unpacker.unpack_utmpidlearr) def Allnames(self): - self.start_call(3) - self.do_call() - list = self.unpacker.unpack_utmpidlearr() - self.end_call() - return list + return self.make_call(3, None, \ + None, self.unpacker.unpack_utmpidlearr) + + +class RnusersClient(PartialRnusersClient, UDPClient): + + def init(self, host): + return UDPClient.init(self, host, 100002, 2) + + +class BroadcastRnusersClient(PartialRnusersClient, BroadcastUDPClient): + + def init(self, bcastaddr): + return BroadcastUDPClient.init(self, bcastaddr, 100002, 2) def test(): import sys - host = '' - if sys.argv[1:]: host = sys.argv[1] + if not sys.argv[1:]: + testbcast() + return + else: + host = sys.argv[1] c = RnusersClient().init(host) list = c.Names() - def strip0(s): - while s and s[-1] == '\0': s = s[:-1] - return s for (line, name, host, time), idle in list: line = strip0(line) name = strip0(name) host = strip0(host) - print name, host, line, time, idle + print `name`, `host`, `line`, time, idle + +def testbcast(): + c = BroadcastRnusersClient().init('<broadcast>') + def listit(list, fromaddr): + host, port = fromaddr + print host + '\t:', + for (line, name, host, time), idle in list: + print strip0(name), + print + c.set_reply_handler(listit) + all = c.Names() + print 'Total Count:', len(all) + +def strip0(s): + while s and s[-1] == '\0': s = s[:-1] + return s + +test() |