diff options
author | Guido van Rossum <guido@python.org> | 1992-09-24 10:33:16 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-09-24 10:33:16 (GMT) |
commit | c8833d4ad39557e870bc10fba3ea598f68dca1fd (patch) | |
tree | 44da9dca9eb3547d4f3d62cc24d0cc52ffbf9d75 /Demo/sockets/mcast.py | |
parent | 590177bc884f9e382afb759e39729d7cae1aa4f1 (diff) | |
download | cpython-c8833d4ad39557e870bc10fba3ea598f68dca1fd.zip cpython-c8833d4ad39557e870bc10fba3ea598f68dca1fd.tar.gz cpython-c8833d4ad39557e870bc10fba3ea598f68dca1fd.tar.bz2 |
Add -b option and sleep shorter.
Diffstat (limited to 'Demo/sockets/mcast.py')
-rwxr-xr-x | Demo/sockets/mcast.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Demo/sockets/mcast.py b/Demo/sockets/mcast.py index 6dab50a..5f16ed9 100755 --- a/Demo/sockets/mcast.py +++ b/Demo/sockets/mcast.py @@ -2,6 +2,7 @@ # After /usr/people/4Dgifts/examples/network/mcast.c # Usage: # mcast -s (sender) +# mcast -b (sender, using broadcast instead multicast) # mcast (receivers) MYPORT = 8123 @@ -14,21 +15,26 @@ from socket import * from SOCKET import * from IN import * -sender = (sys.argv[1:2] == ['-s']) +sender = sys.argv[1:] s = socket(AF_INET, SOCK_DGRAM) if sender: - # Ugly: construct decimal IP address string from MYGROUP_BYTES - mygroup = '' - for byte in MYGROUP_BYTES: mygroup = mygroup + '.' + `byte` - mygroup = mygroup[1:] - ttl = struct.pack('b', 1) # Time-to-live - s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, ttl) + if sys.argv[1] == '-b': + s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) + mygroup = '<broadcast>' + else: + # Ugly: construct decimal IP address string from MYGROUP_BYTES + mygroup = '' + for byte in MYGROUP_BYTES: mygroup = mygroup + '.' + `byte` + mygroup = mygroup[1:] + ttl = struct.pack('b', 1) # Time-to-live + s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, ttl) while 1: - data = `time.time()` + '\n' + data = `time.time()` +## data = data + (1400 - len(data)) * '\0' s.sendto(data, (mygroup, MYPORT)) - time.sleep(5) + time.sleep(1) else: # Bind the socket to my port s.bind('', MYPORT) |