Better-ish client
This commit is contained in:
parent
1d58d87ef4
commit
9243978b0e
@ -19,6 +19,17 @@ sp = pUp(s)
|
|||||||
|
|
||||||
# script start
|
# script start
|
||||||
import socket
|
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):
|
def sendRequest(connection,data):
|
||||||
connection.sendall(len(data).to_bytes(4,"big") + data)
|
connection.sendall(len(data).to_bytes(4,"big") + data)
|
||||||
@ -39,23 +50,19 @@ def main():
|
|||||||
global connection
|
global connection
|
||||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
connection.connect(("127.0.0.1",21779))
|
connection.connect(("127.0.0.1",21779))
|
||||||
|
thread = receiverThread(connection)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
text = input("data: ")
|
text = input()
|
||||||
data = text.encode("utf-8")
|
data = text.encode("utf-8")
|
||||||
|
|
||||||
|
connection.settimeout(15)
|
||||||
sendRequest(connection,data)
|
sendRequest(connection,data)
|
||||||
response = getResponse(connection).decode("utf-8")
|
connection.settimeout(None)
|
||||||
print("server: " +response)
|
|
||||||
|
|
||||||
if text == "exit":
|
if text == "exit":
|
||||||
connection.close()
|
connection.close()
|
||||||
break
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user