From 9243978b0eb8d08f669866e1d59bca695ece19c4 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Fri, 9 Apr 2021 23:46:48 +0200 Subject: [PATCH] Better-ish client --- serverBlaster.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/serverBlaster.py b/serverBlaster.py index c6a403a..d34b6b2 100644 --- a/serverBlaster.py +++ b/serverBlaster.py @@ -19,6 +19,17 @@ sp = pUp(s) # script start import socket +import threading + +class receiverThread(threading.Thread): + def __init__(self,connection): + threading.Thread.__init__(self) + self.connection = connection + + def run(self): + while True: + response = getResponse(connection).decode("utf-8") + print("server: " +response) def sendRequest(connection,data): connection.sendall(len(data).to_bytes(4,"big") + data) @@ -39,23 +50,19 @@ def main(): global connection connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) connection.connect(("127.0.0.1",21779)) + thread = receiverThread(connection) + thread.start() + while True: - text = input("data: ") + text = input() data = text.encode("utf-8") + + connection.settimeout(15) sendRequest(connection,data) - response = getResponse(connection).decode("utf-8") - print("server: " +response) - + connection.settimeout(None) if text == "exit": connection.close() break - - if text == "close": - connection.close() - connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - connection.connect(("127.0.0.1",21779)) - connection.close() - break if __name__ == '__main__': main() \ No newline at end of file