Last active
December 9, 2021 02:04
-
-
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
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
# 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)) |
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
# 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