You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
687 B
Python

# создание сокета, таймауты и обработка ошибок
# сервер
import socket
with socket.socket() as sock:
sock.bind(("", 10001))
sock.listen()
while True:
conn, addr = sock.accept()
conn.settimeout(5) # timeout := None|0|gt 0
with conn:
while True:
try:
data = conn.recv(1024)
except socket.timeout:
print("close connection by timeout")
break
if not data:
break
print(data.decode("utf8"))