import socket IP = "127.0.0.1" PORT = 5050 BUFSIZ = 2048 client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_addr = (IP, PORT) client.connect(client_addr) try: check_command = True while check_command: msg = input("Client:") if msg != '': client.send(bytes(msg, "utf-8")) if msg == "quit": check_command = False elif msg == "login": #Send USERNAME msg = input("Username:") client.send(bytes(msg, "utf-8")) #Send PASSWORD msg = input("Password:") client.send(bytes(msg, "utf-8")) data = client.recv(BUFSIZ) if data.decode("utf-8") == "Login successful": data = client.recv(BUFSIZ) print(data.decode("utf-8")) msg = input("Client:") client.send(bytes(msg, "utf-8")) #else login false chua lam else: check_command = False elif msg == "register": check_command = False data = client.recv(BUFSIZ) print(data.decode("utf-8")) else: print("Use for help!\n") finally: print("Left the Server!") client.close()