Skip to content

Instantly share code, notes, and snippets.

@dksmiffs
Last active December 9, 2021 02:04
Show Gist options
  • Save dksmiffs/f085b8cfb38680c103c6fe9226d01c0b to your computer and use it in GitHub Desktop.
Save dksmiffs/f085b8cfb38680c103c6fe9226d01c0b to your computer and use it in GitHub Desktop.
Python 3 UDP example, with only very minor modifications needed to this guidance: https://wiki.python.org/moin/UdpCommunication
# Simple example that receives UDP messages using Python 3
# Guidance: https://wiki.python.org/moin/UdpCommunication
import socket
UDP_IP = '127.0.0.1'
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
print(sock.recv(10240))
# Simple example that sends UDP message using Python 3
# Guidance: https://wiki.python.org/moin/UdpCommunication
import socket
UDP_IP = '127.0.0.1'
UDP_PORT = 5005
MESSAGE = b'Hello, UDP!'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment