# ------------------------------------------------------------
# Copyright © 2026/2027 Dr. Mohammad Alja'afreh. All rights reserved.
# PSUT IoT Engineering Learning Platform
# ------------------------------------------------------------
# ---- Runs on the Raspberry Pi gateway  (IP 192.168.1.20)
import socket
 
# UDP socket: SOCK_DGRAM = datagrams, no connection.
rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 0.0.0.0 receives unicast to .20 AND broadcasts to .255
rx.bind(('0.0.0.0', 7000))
while True:
    # One whole datagram + the sender's (IP, port).
    data, addr = rx.recvfrom(1024)
    print(addr, '->', data.decode())
