Created
August 16, 2010 18:11
-
-
Save jbalogh/527442 to your computer and use it in GitHub Desktop.
A server that accepts a connection and then hangs.
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
""" | |
A server that accepts a connection and then hangs. Pass a number to bind to a | |
specific port. | |
You need socket.settimeout. | |
""" | |
import socket | |
import sys | |
def main(port): | |
server = socket.socket() | |
server.bind(('localhost', port)) | |
server.listen(1) | |
print 'Listening on localhost:%s' % port | |
while 1: | |
try: | |
server.accept() | |
print 'Got a connection, dropping it in a hole' | |
except KeyboardInterrupt: | |
break | |
if __name__ == '__main__': | |
port = int(sys.argv[1]) if len(sys.argv) > 1 else 9999 | |
main(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment