Last active
August 29, 2015 14:22
-
-
Save kratsg/54ffb2fd0836cf8800a7 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 | |
""" | |
A simple echo client | |
""" | |
import select | |
import socket | |
import sys | |
from socket import AF_INET, SOCK_STREAM, timeout | |
host = "localhost" | |
port = 8023 | |
size = 1024 | |
s = socket.socket(AF_INET, SOCK_STREAM) | |
running = 1 | |
s.connect((host,port)) | |
s.send(bytes('Hello, I am connected to you.', 'UTF-8')) | |
while running: | |
try: | |
inputready,outputready,exceptready = select.select([sys.stdin],[],[]) | |
for s in inputready: | |
if s == sys.stdin: | |
# handle standard input | |
junk = sys.stdin.readline() | |
running = 0 | |
else: | |
data = s.recv(size) | |
print ('Recieved:', repr(data)) | |
s.shutdown(1) | |
except timeout: | |
s.send (bytes('I am closed now, bye.', 'UTF-8')) | |
break | |
print ('I shut down, bye forever') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment