upd client and server
This commit is contained in:
commit
7946693d7b
11
udp_client.py
Normal file
11
udp_client.py
Normal 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
13
udp_server.py
Normal 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)
|
||||||
Loading…
Reference in New Issue
Block a user