Last active
December 2, 2018 20:34
-
-
Save adyavanapalli/4c681f886bff471c9fc081ef51fda3dc to your computer and use it in GitHub Desktop.
Send single byte payloads via UDP on a LAN.
This file contains hidden or 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
#!/usr/bin/env python3 | |
'''Sends a single byte payload to the specified IP address on UDP port 8080. | |
Should be run on the Intel Edison. | |
''' | |
import socket | |
# TARGET IP address should be that of the device you're running `server.py`. | |
TARGET = ('192.168.1.1', 8080) | |
MESSAGE = b'0' | |
def main(): | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: | |
while True: | |
sock.sendto(MESSAGE, TARGET) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or 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
#!/usr/bin/env python3 | |
'''Listens for a single byte payload on UDP port 8080 on all interfaces. | |
Should be run on any device != Intel Edison. | |
''' | |
import socket | |
HOST = ('0.0.0.0', 8080) | |
def main(): | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: | |
sock.bind(HOST) | |
while True: | |
data, addr = sock.recvfrom(1) | |
print('Received {} from {}'.format(data.decode(), addr)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment