Skip to content

Instantly share code, notes, and snippets.

@elikoga
Created September 18, 2020 06:52
Show Gist options
  • Save elikoga/9499481404420039bbd4b065f3e221c2 to your computer and use it in GitHub Desktop.
Save elikoga/9499481404420039bbd4b065f3e221c2 to your computer and use it in GitHub Desktop.
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = b"Hello, World!"
print("UDP target IP: %s" % UDP_IP)
print("UDP target port: %s" % UDP_PORT)
print("message: %s" % MESSAGE)
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print("received message: %s" % data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment