Created
June 16, 2013 15:01
-
-
Save o3bvv/5792312 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
import socket | |
import select | |
import sys | |
from threading import Thread | |
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) | |
sock.connect( ('192.168.1.36', 20001) ) | |
def client_runner(): | |
while True: | |
try: | |
rlist, wlist, elist = select.select([sock], [sock], [], 0) | |
except socket.error, e: | |
print "A socket error" | |
break | |
if [rlist, wlist, elist] != [ [], [], [] ]: | |
line = sock.recv(200).rstrip() | |
if line.endswith("\\n"): | |
line = line[:-2] | |
if line.endswith("quit"): | |
break | |
if line.startswith("\u0020"): | |
line = line[6:] | |
print line | |
t = Thread(target = client_runner) | |
t.daemon = True | |
t.start() | |
while True: | |
line = sys.stdin.readline() | |
if not line: | |
break | |
sock.send(line) | |
if line.rstrip() in ["quit", "exit"]: | |
break | |
sock.close() | |
if t.is_alive(): | |
t.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment