# ------------------------------------------------------------
# Copyright © 2026/2027 Dr. Mohammad Alja'afreh. All rights reserved.
# PSUT IoT Engineering Learning Platform
# ------------------------------------------------------------
import socket
 
# ---- UDP socket: SOCK_DGRAM = datagrams, no connection.
rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
rx.bind(('127.0.0.1', 7000))      # listen on UDP port 7000
print('UDP receiver ready on 127.0.0.1:7000', flush=True)
 
while True:
    # One whole datagram + the sender's (IP, port).
    data, addr = rx.recvfrom(1024)
    print('from', addr[0], data.decode())
