Created
December 19, 2016 23:22
-
-
Save pijyoi/f8e48d8ce3d7154d27e9b09ca112a9de to your computer and use it in GitHub Desktop.
udp broadcast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
sock = socket.socket(type=socket.SOCK_DGRAM) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
sock.bind(('192.168.0.255', 12345)) | |
while 1: | |
data, addr = sock.recvfrom(100) | |
print(data, addr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
sock = socket.socket(type=socket.SOCK_DGRAM) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
dst = ('192.168.0.255', 12345) | |
cnt = 0 | |
while 1: | |
msg = '{:04d}'.format(cnt) | |
sock.sendto(msg.encode(), dst) | |
cnt += 1 | |
time.sleep(1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment