Skip to content

Commit d53ec56

Browse files
committed
new examples
1 parent c29dae4 commit d53ec56

File tree

2 files changed

+26
-77
lines changed

2 files changed

+26
-77
lines changed
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1+
#!/usr/bin/env python3
2+
13
import socket
24

35
HOST, PORT = '', 8888
46

57
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
9+
# to solve problem with
610
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
11+
712
listen_socket.bind((HOST, PORT))
813
listen_socket.listen(1)
914

1015
print(f'Serving HTTP on port {PORT} ...')
1116

1217
while True:
13-
print ('1 - start')
14-
client_connection, client_address = listen_socket.accept()
18+
19+
# ---
20+
21+
print('start ')
22+
23+
# --- accept new client ---
1524

25+
client_connection, client_address = listen_socket.accept()
26+
27+
# --- receive request ---
28+
1629
request_data = b''
1730

1831
while True:
19-
chunk = client_connection.recv(1)
20-
request_data += chunk
21-
print(chunk)
22-
if request_data.endswith(b'\r\n\r\n'):
32+
request_data += client_connection.recv(1) # get by char to easier recognize end of header
33+
if request_data.endswith(b'\r\n\r\n'): # recognize end of header - empty line
2334
break
2435

2536
print(request_data.decode('utf-8'))
2637

38+
# --- send response ---
39+
2740
client_connection.sendall(b"""HTTP/1.1 200 OK\n\nHello, World 3@!\n""")
41+
42+
# --- close connection to client ---
43+
2844
client_connection.close()
29-
print ('2 - end')
45+
46+
# ----
47+
48+
print('end')

turtle/pattern-rectangle-circle/Niezapisany dokument 1

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)