Last active
August 29, 2015 14:07
-
-
Save ninehills/76f8a4dee9a9c79cc498 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
# a simple multi-threaded TCP Black Hole server | |
import sys | |
from socket import * | |
import threading | |
import thread | |
import time | |
def handler(clientsock,addr): | |
try: | |
while 1: | |
data = clientsock.recv(65535); | |
if not data: | |
break | |
finally: | |
print 'connection close...' | |
clientsock.close() | |
if __name__ == '__main__': | |
HOST = '0.0.0.0' | |
PORT = int(sys.argv[1]) | |
BUFSIZ = 65535 | |
ADDR = (HOST, PORT) | |
serversock = socket(AF_INET, SOCK_STREAM) | |
serversock.bind(ADDR) | |
serversock.listen(5) | |
while 1: | |
print 'waiting for connection...' | |
clientsock, addr = serversock.accept() | |
print '...connected from: ', addr | |
thread.start_new_thread(handler, (clientsock, addr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment