import socket
import time

counter = 0
total_bytes = 0

server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind(('0.0.0.0', 10002))
print("UDP сервер запущен (со статистикой)")

while True:
    data, addr = server.recvfrom(1024)
    counter += 1
    total_bytes += len(data)

    original = data.decode()

    modified = f"[#{counter}] [байт:{len(data)}] [всего:{total_bytes}] {original.upper()}"

    print(f"Пакет #{counter} от {addr}: {original} -> {modified}")
    server.sendto(modified.encode(), addr)