from threading import Thread
from SecureSocketService import Socket
from sys import exit
from socket import error as socket_error
class Client(Socket):
def __init__(self, host: str, port: int, service_id: int = 2):
super().__init__()
self.service_id = service_id
print("Connecting...")
self.connect_server(host, port)
Thread(target=self.receive_server).start()
Thread(target=self.send_input).start()
def receive_server(self):
while True:
try:
data = self.receive(self.socket)
except socket_error:
self.quit()
else:
if data.lower() == "quit":
break
print(data)
def send_server(self, data):
self.send(self.socket, data)
def send_input(self):
data = input()
self.send_server(data)
def quit(self):
self.socket.close()
pass
finally:
print("Disconnected")
exit()
if __name__ == "__main__":
Client("localhost", 3621)