Skip to content

Instantly share code, notes, and snippets.

@jshs

jshs/stress.py Secret

Created February 17, 2015 15:40
Simultaneous HTTP connections with keepalive
#!/usr/bin/env python3
import socket
PORT = 8080
NCLIENTS = 20
socks = []
for i in range(NCLIENTS):
s = socket.socket()
s.connect(("localhost", PORT))
print("{}: sending request".format(i))
s.sendall("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n".encode())
s.recv(1)
print("{}: response received".format(i))
socks.append(s)
print("all sockets have received data")
for s in socks:
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment