broadcast.py 283 Bytes
Newer Older
Guido van Rossum's avatar
Guido van Rossum committed
1 2 3 4 5 6 7 8
# Send UDP broadcast packets

MYPORT = 50000

import sys, time
from socket import *

s = socket(AF_INET, SOCK_DGRAM)
Guido van Rossum's avatar
Guido van Rossum committed
9
s.bind(('', 0))
10
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
Guido van Rossum's avatar
Guido van Rossum committed
11 12

while 1:
13 14 15
    data = repr(time.time()) + '\n'
    s.sendto(data, ('<broadcast>', MYPORT))
    time.sleep(2)