Python Forum

Full Version: Help Sending Socket Data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I'm trying to create a chat room with socket.

The messages from the other user only show up when the other user types in a message.

import socket

HEADER = 64
PORT = 
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = "!DISCONNECT"
SERVER = 
ADDR = (SERVER, PORT)

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

def send(msg):
    message = msg.encode(FORMAT)
    msg_length = len(message)
    send_length = str(msg_length).encode(FORMAT)
    send_length += b' ' * (HEADER - len(send_length))
    client.send(send_length)
    client.send(message)
    print(client.recv(2048).decode(FORMAT))


while True:
    message = str(input("Message: "))
    send(message)
(I'm new to posting, sorry if I don't format everything properly)