upd client and server

This commit is contained in:
Drac0 2026-05-04 10:48:20 +03:00
commit 7946693d7b
2 changed files with 24 additions and 0 deletions

11
udp_client.py Normal file
View File

@ -0,0 +1,11 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = input("Введите сообщение: ")
client.sendto(message.encode(), ('127.0.0.1', 10001))
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

13
udp_server.py Normal file
View File

@ -0,0 +1,13 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind(('0.0.0.0', 10001))
print("UDP сервер запущен")
while True:
data, addr = server.recvfrom(1024)
print(f"Сообщение от {addr}: {data.decode()}")
response = data.upper()
server.sendto(response, addr)