main/03_networking/udp_client.py

17 lines
545 B
Python

import socket
HOST, PORT = '127.0.0.1', 10001
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client:
messages = ["Привет UDP!", "Тест пакета", "exit"]
for msg in messages:
print(f"📤 Отправляю UDP: {msg}")
client.sendto(msg.encode(), (HOST, PORT))
if msg.lower() == 'exit':
break
data, _ = client.recvfrom(1024)
print(f"📥 Ответ: {data.decode().strip()}")
print("✅ UDP клиент завершил работу.")