Last active
August 3, 2023 10:42
-
-
Save oliora/231a7347cfd1eb1cc2329fee90db24f8 to your computer and use it in GitHub Desktop.
Trivial UDP receiver in Python
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
# Run it like `python3 udp-receiver.py 0.0.0.0 <listening_port>` | |
import socket | |
import sys | |
with socket.socket(type=socket.SOCK_DGRAM) as s: | |
s.bind((sys.argv[1], int(sys.argv[2]))) | |
while True: | |
(data, ancdata, msg_flags, address) = s.recvmsg(1024) | |
print(f'Received "{data.decode()}", ancdata="{ancdata}", sender={address}, flags={msg_flags}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment