-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpstuff3.py
More file actions
28 lines (21 loc) · 785 Bytes
/
tcpstuff3.py
File metadata and controls
28 lines (21 loc) · 785 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
26
27
28
import socket
IP = '0.0.0.0'
PORT = 8080
MAXIMUM_QUEUE_SIZE = 0
BUFFER_SIZE = 2048
def respond(client_socket, client_ip_and_port):
request = client_socket.recv(BUFFER_SIZE).decode()
response = "HTTP/1.1 200 OK\n\nhi there\n".encode()
client_socket.send(response)
def serverloop():
listening_socket = socket.socket()
listening_socket.bind((IP, PORT))
listening_socket.listen(MAXIMUM_QUEUE_SIZE)
while True:
(client_socket, client_ip_and_port) = listening_socket.accept()
respond(client_socket, client_ip_and_port)
client_socket.close()
if __name__ == '__main__': # is this file executed directly (not just imported)
print('Server launched on %s:%s, press ctrl+c to kill the server'
% (IP, PORT))
serverloop()