import socket

host = socket.gethostname()  # Or the server's IP address if not on the same machine
port = 1223

try:
    cs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # Create socket
    cs.connect((host, port))  # Connect to the server
    print("Socket created successfully")

    while True:
        msg1 = input("Enter message to send: ")
        s = msg1.encode()  # Encode the message to bytes
        cs.send(s)  # Send the message
        s1 = cs.recv(2048)  # Receive the response (up to 2048 bytes)
        s2 = s1.decode()  # Decode the response to a string
        print("Reversed string from server is: %s" % s2)

        if msg1.lower() == "exit":
            break

    cs.close()  # Close the socket

except socket.error as msg1:
    print("Unable to connect server with error %s" % msg1)
