-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
24 lines (19 loc) · 782 Bytes
/
main.py
File metadata and controls
24 lines (19 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import socket
def run_server(host='127.0.0.1', port=65432):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
server_socket.bind((host, port))
print(f"Сервер запущен на {host}:{port}")
server_socket.listen(1)
print("Ожидание подключения")
conn, addr = server_socket.accept()
with conn:
print(f"Подключено")
while True:
data = conn.recv(1024)
if not data:
break
print(f"Получено сообщение: {data.decode('utf-8')}")
conn.sendall(data)
print("Соединение закрыто")
if __name__ == "__main__":
run_server()