Created
June 8, 2011 22:52
-
-
Save bnoordhuis/1015643 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 | |
import socket | |
import sys | |
host, port = sys.argv[1:] | |
host = socket.gethostbyname(host) | |
port = int(port) | |
sock = socket.socket() | |
sock.connect((host, port)) | |
sock.settimeout(1.0) | |
while True: | |
data = sys.stdin.read(64) | |
if not data: | |
break | |
sys.stdout.write(data) | |
while data: | |
size = sock.send(data) | |
data = data[size:] | |
while True: | |
try: | |
data = sock.recv(512) | |
except socket.timeout: | |
break | |
if not data: | |
break | |
sys.stdout.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment