#!/usr/bin/env python from socket import socket, AF_INET, SOCK_DGRAM # socket.AF_INET: IPv4 # socket.AF_INET6: IPv6 # socket.AF_UNIX: unix sockets # socket.SOCK_DGRAM: datagram (UDP) udp_socket = socket(AF_INET, SOCK_DGRAM) # bind creates a server (listener) # connect creates a client udp_socket.bind(("127.0.0.1", 64512)) while True: # reads up to 1024 Bytes message, address = udp_socket.recvfrom(1024) # decode() converts bytes[] to a String print("Message from " + str(address) + " with text: " + message.decode())