Better-ish client

This commit is contained in:
Fierelier 2021-04-09 23:46:48 +02:00
parent 1d58d87ef4
commit 9243978b0e
1 changed files with 18 additions and 11 deletions

View File

@ -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()