Last active
December 16, 2015 10:09
-
-
Save joshkunz/5418359 to your computer and use it in GitHub Desktop.
Simple telnet-like socket interface.
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
import socket | |
import threading | |
import argparse | |
LINE_TERM = "\n" | |
parser = argparse.ArgumentParser() | |
parser.add_argument("host", help="The host name of the server.") | |
parser.add_argument("port", type=int, help="Port of the server.") | |
args = parser.parse_args() | |
cnxn = socket.create_connection((args.host, args.port)) | |
def recv_msgs(): | |
data = cnxn.recv(1024) | |
print data, | |
threading.Thread(target=recv_msgs).start() | |
print "Connected to {0}:{1}".format(args.host, args.port) | |
print "^C to quit..." | |
try: | |
while True: | |
line = raw_input() | |
cnxn.sendall(line + LINE_TERM) | |
except socket.error, e: | |
print e | |
except KeyboardInterrupt: | |
print "Disconnecting..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment