Created
December 29, 2013 04:57
-
-
Save linmic/8167604 to your computer and use it in GitHub Desktop.
listening tcp
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/python | |
import socket | |
HOST = 'localhost' # use '' to expose to all networks | |
PORT = 515 | |
def incoming(host, port): | |
"""Open specified port and return file-like object""" | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
sock.bind((host, port)) | |
sock.listen(0) | |
request, addr = sock.accept() | |
return request.makefile('r', 0) | |
for line in incoming(HOST, PORT): | |
print line, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment