-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (20 loc) · 763 Bytes
/
main.py
File metadata and controls
25 lines (20 loc) · 763 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
25
import socket
# SOCK_STREAM - поддержка протокола tcp
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Отключаем задержку по портам
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(('localhost', 5000))
server_socket.listen()
while True:
print('Before .accept()')
client_socket, addr = server_socket.accept()
print('Connection addr ', addr)
while True:
print('Before .recv()')
request = client_socket.recv(4096)
if not request:
break
else:
response = 'Hello world!\n\r'.encode() # Преобраовываем в bytes
client_socket.send(response)
client_socket.close()