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.
34 lines
902 B
Python
34 lines
902 B
Python
import socket
|
|
import time
|
|
|
|
SERVER_ADDRESS = (HOST, PORT) = '', 8888
|
|
REQUEST_QUEUE_SIZE = 5
|
|
|
|
|
|
def handle_request(client_connection):
|
|
request = client_connection.recv(1024)
|
|
print(request.decode())
|
|
http_response = b"""\
|
|
HTTP/1.1 200 OK
|
|
|
|
Hello Slow Loris!
|
|
"""
|
|
client_connection.sendall(http_response)
|
|
time.sleep(20) #spleep a bit, cause sending is tiring
|
|
|
|
|
|
def serve_forever():
|
|
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
listen_socket.bind(SERVER_ADDRESS)
|
|
listen_socket.listen(REQUEST_QUEUE_SIZE)
|
|
print('Waiting for slow loris on port {port} ...'.format(port=PORT))
|
|
|
|
while True:
|
|
client_connection, client_address = listen_socket.accept()
|
|
handle_request(client_connection)
|
|
client_connection.close()
|
|
|
|
if __name__ == '__main__':
|
|
serve_forever()
|