Skip to content

Instantly share code, notes, and snippets.

@jbalogh
Created August 16, 2010 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbalogh/527442 to your computer and use it in GitHub Desktop.
Save jbalogh/527442 to your computer and use it in GitHub Desktop.
A server that accepts a connection and then hangs.
"""
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