Guido van Rossum | b83ec8f | 1992-05-19 13:52:02 +0000 | [diff] [blame] | 1 | # Send UDP broadcast packets |
| 2 | |
| 3 | MYPORT = 50000 |
| 4 | |
| 5 | import sys, time |
| 6 | from socket import * |
| 7 | |
| 8 | s = socket(AF_INET, SOCK_DGRAM) |
Guido van Rossum | 00d5974 | 1994-10-08 19:13:48 +0000 | [diff] [blame] | 9 | s.bind(('', 0)) |
Guido van Rossum | 0aead9f | 1992-09-08 21:20:12 +0000 | [diff] [blame] | 10 | s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) |
Guido van Rossum | b83ec8f | 1992-05-19 13:52:02 +0000 | [diff] [blame] | 11 | |
| 12 | while 1: |
Tim Peters | e6ddc8b | 2004-07-18 05:56:09 +0000 | [diff] [blame] | 13 | data = repr(time.time()) + '\n' |
| 14 | s.sendto(data, ('<broadcast>', MYPORT)) |
| 15 | time.sleep(2) |