import socket

PORT = 5050
SERVER = socket.gethostbyname(socket.gethostname())
ADDR = (SERVER, PORT)
FORMAT = "utf-8"
LEN = 64

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)


def send_msg(msg):
    message = msg.encode(FORMAT)
    msg_length = len(message)
    send_length = str(msg_length).encode(FORMAT)
    send_length = b' ' * (LEN - len(send_length))
    client.send(send_length)
    client.send(str(msg_length).encode(FORMAT))
    client.send(message)


send_msg("Hello, Kevin")
send_msg("Hello, Peter")
send_msg("DISCONNECTED")
