Skip to content

Instantly share code, notes, and snippets.

@brettbeeson
Created January 12, 2024 07:23
Show Gist options
  • Save brettbeeson/e2a2188d950de48d5561897c515f4a68 to your computer and use it in GitHub Desktop.
Save brettbeeson/e2a2188d950de48d5561897c515f4a68 to your computer and use it in GitHub Desktop.
Echo bytes from UDP port to stdout, treating as utf-8
#!/usr/bin/env python3
# Based on: David Manouchehri <manouchehri@protonmail.com>
# Echo bytes from UDP port to stdout, treating as utf-8
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = '0.0.0.0'
server_port = 22222
server = (server_address, server_port)
sock.bind(server)
print("Listening on ", server_address, ":", str(server_port), flush=True)
while True:
payload, client_address = sock.recvfrom(1000)
print(payload.decode(),end='',flush=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment