Created
December 5, 2012 01:22
-
-
Save acg/4211098 to your computer and use it in GitHub Desktop.
Factoring out the listen(2) half of djb's tcpserver.
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
#!/usr/bin/env python | |
import sys | |
import os | |
import socket | |
port = sys.argv.pop(0) | |
host = sys.argv.pop(0) | |
port = int(sys.argv.pop(0)) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((host, port)) | |
s.listen(32) | |
os.dup2(s.fileno(),0) | |
os.close(s.fileno()) | |
os.execvp(sys.argv[0],sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment