Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created June 8, 2011 22:52
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 bnoordhuis/1015643 to your computer and use it in GitHub Desktop.
Save bnoordhuis/1015643 to your computer and use it in GitHub Desktop.
#!/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