PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 18ms app.codeStats 1ms

/Demo/sockets/broadcast.py

http://unladen-swallow.googlecode.com/
Python | 15 lines | 11 code | 3 blank | 1 comment | 0 complexity | 163bd13a32e5ab5f0fdd459450904df3 MD5 | raw file
 1# Send UDP broadcast packets
 2
 3MYPORT = 50000
 4
 5import sys, time
 6from socket import *
 7
 8s = socket(AF_INET, SOCK_DGRAM)
 9s.bind(('', 0))
10s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
11
12while 1:
13    data = repr(time.time()) + '\n'
14    s.sendto(data, ('<broadcast>', MYPORT))
15    time.sleep(2)