Last active
March 9, 2016 07:28
-
-
Save agalera/21de08d7f4e3421a6ec0 to your computer and use it in GitHub Desktop.
Many connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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