mirror of https://github.com/python/cpython.git
Add -b option and sleep shorter.
This commit is contained in:
parent
590177bc88
commit
c8833d4ad3
|
@ -2,6 +2,7 @@
|
||||||
# After /usr/people/4Dgifts/examples/network/mcast.c
|
# After /usr/people/4Dgifts/examples/network/mcast.c
|
||||||
# Usage:
|
# Usage:
|
||||||
# mcast -s (sender)
|
# mcast -s (sender)
|
||||||
|
# mcast -b (sender, using broadcast instead multicast)
|
||||||
# mcast (receivers)
|
# mcast (receivers)
|
||||||
|
|
||||||
MYPORT = 8123
|
MYPORT = 8123
|
||||||
|
@ -14,21 +15,26 @@
|
||||||
from SOCKET import *
|
from SOCKET import *
|
||||||
from IN import *
|
from IN import *
|
||||||
|
|
||||||
sender = (sys.argv[1:2] == ['-s'])
|
sender = sys.argv[1:]
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_DGRAM)
|
s = socket(AF_INET, SOCK_DGRAM)
|
||||||
|
|
||||||
if sender:
|
if sender:
|
||||||
# Ugly: construct decimal IP address string from MYGROUP_BYTES
|
if sys.argv[1] == '-b':
|
||||||
mygroup = ''
|
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
|
||||||
for byte in MYGROUP_BYTES: mygroup = mygroup + '.' + `byte`
|
mygroup = '<broadcast>'
|
||||||
mygroup = mygroup[1:]
|
else:
|
||||||
ttl = struct.pack('b', 1) # Time-to-live
|
# Ugly: construct decimal IP address string from MYGROUP_BYTES
|
||||||
s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, ttl)
|
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:
|
while 1:
|
||||||
data = `time.time()` + '\n'
|
data = `time.time()`
|
||||||
|
## data = data + (1400 - len(data)) * '\0'
|
||||||
s.sendto(data, (mygroup, MYPORT))
|
s.sendto(data, (mygroup, MYPORT))
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
# Bind the socket to my port
|
# Bind the socket to my port
|
||||||
s.bind('', MYPORT)
|
s.bind('', MYPORT)
|
||||||
|
|
Loading…
Reference in New Issue