Skip to content

Instantly share code, notes, and snippets.

@murilopontes
Last active August 14, 2016 11:37
Show Gist options
  • Save murilopontes/414dd7fa5222d6a4d216a5e0e4e324be to your computer and use it in GitHub Desktop.
Save murilopontes/414dd7fa5222d6a4d216a5e0e4e324be to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import threading
import time
import socket
import os
import sys
import resource
import subprocess
class simple_tcp_server(threading.Thread):
def __init__(self,tcp_port):
threading.Thread.__init__(self)
self.tcp_port = tcp_port
def run(self):
print threading.current_thread().name, "tcp_port=", self.tcp_port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("0.0.0.0",self.tcp_port))
s.listen(1)
while True:
conn,addr=s.accept()
print "conaddr=",addr,self.tcp_port,
while True:
data=conn.recv(1024)
if not data: break
print "RX=", data
conn.send(data)
conn.close()
if __name__ == "__main__":
threads = []
print "create"
for tcp_port in range(65536):
t=simple_tcp_server(tcp_port)
threads.append(t)
print "start"
for t in threads:
t.start()
print "\r\nactive threads",threading.active_count()
print "join"
for t in threads:
t.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment