From 3a8afeb369d4ef66c9b991e64febe66a35338177 Mon Sep 17 00:00:00 2001 From: Wango Fett Date: Thu, 26 Oct 2017 17:05:49 +0000 Subject: Pip installable! --- asciifarm/client/connection.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 asciifarm/client/connection.py (limited to 'asciifarm/client/connection.py') diff --git a/asciifarm/client/connection.py b/asciifarm/client/connection.py new file mode 100644 index 0000000..9ca2ccc --- /dev/null +++ b/asciifarm/client/connection.py @@ -0,0 +1,27 @@ + +import socket + +from .tcommunicate import send, receive + +class Connection: + + def __init__(self, socketType): + if socketType == "abstract" or socketType == "unix": + sockType = socket.AF_UNIX + elif socketType == "inet": + sockType = socket.AF_INET + self.sock = socket.socket(sockType, socket.SOCK_STREAM) + + def connect(self, address): + self.sock.connect(address) + + def listen(self, callback, onError): + while True: + try: + data = receive(self.sock) + except Exception as err: + onError(err) + callback(data) + + def send(self, message): + send(self.sock, bytes(message, 'utf-8')) -- cgit