Skip to content

Instantly share code, notes, and snippets.

@agalera
Last active March 9, 2016 07:28
Show Gist options
  • Save agalera/21de08d7f4e3421a6ec0 to your computer and use it in GitHub Desktop.
Save agalera/21de08d7f4e3421a6ec0 to your computer and use it in GitHub Desktop.
Many connection
from threading import Thread
import sys
import socket
host, port = sys.argv[1], int(sys.argv[2])
connect_per_thread = int(sys.argv[4])
def many_connection():
while True:
sockets = []
try:
for x in xrange(connect_per_thread):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockets.append(s)
s.connect((host, port))
for x in sockets:
x.recv(1)
x.close()
except:
pass
for x in xrange(int(sys.argv[3])):
many_connection_t = Thread(target=many_connection)
many_connection_t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment