1 часть: Добавлен TCP сервер и клиент

This commit is contained in:
Дмитрий Зязев 2026-04-28 18:00:25 +03:00
parent b7ccb16c7c
commit a54b70d43e
2 changed files with 29 additions and 0 deletions

8
src/TCP-client.py Normal file
View File

@ -0,0 +1,8 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 10001))
client.sendall(b'exit')
data = client.recv(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

21
src/TCP-server.py Normal file
View File

@ -0,0 +1,21 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("0.0.0.0", 10001))
server.listen(1)
print("TCP сервер запущен")
while True:
conn, addr = server.accept()
print(f"Подключение от {addr}")
data = conn.recv(1024)
if not data:
break
conn.sendall(data.upper())
conn.close()
if data.upper() == b'EXIT':
break