Last active
May 28, 2017 09:43
-
-
Save yingshaoxo/7b5fe8f20186c64623c410972ac4f776 to your computer and use it in GitHub Desktop.
asyncore TCP client
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 asyncore | |
import threading | |
class MySocketClient(asyncore.dispatcher): | |
def __init__(self, server_address): | |
asyncore.dispatcher.__init__(self) | |
self.create_socket() | |
self.connect(server_address) | |
def handle_read(self): | |
data = self.recv(8192) | |
if data: | |
print(data) | |
client = MySocketClient(('127.0.0.1', 5920)) | |
threading.Thread(target=asyncore.loop).start() | |
while True: | |
sending_text = '' | |
while sending_text == '': | |
sending_text = input('\nSay somethine: ') | |
client.send(sending_text.encode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment