Commit 9663b53d authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Initial checkin.

parent eb8879bc
import socket
import select
import sys
import string
import regsub
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
host=sys.argv[1]
port=string.atoi(sys.argv[2])
pfx = ""
metapfx = ""
if len(sys.argv) > 3:
pfx = sys.argv[3] + ": "
metapfx = sys.argv[3] + "meta: "
print metapfx + "Connecting to", host, port
s.connect((host, port))
print metapfx + "Connected"
needpfx = 1
while 1:
(i, o, e) = select.select([s, sys.stdin], [], [])
if s in i:
d = s.recv(512)
if d == "":
if needpfx == 0:
print
if pfx == "":
sys.exit(0)
else:
print metapfx + "EOF on socket"
sys.stdin.readline()
sys.exit(0)
line = ""
if needpfx:
line = pfx
needpfx = 0
if d[-1] == '\n':
d = d[:-1]
needpfx = 1
line = line + regsub.gsub("\n", "\n" + pfx, d)
if needpfx == 1:
line = line + "\n"
sys.stdout.write(line)
sys.stdout.flush()
if sys.stdin in i:
d = sys.stdin.readline()
if d == "":
print metapfx + "EOF on stdin"
sys.exit(1)
s.send(d)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment