Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Sending Socket Data
#1
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)
Larz60+ write Sep-23-2021, 04:29 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending data from the form to DB quisatz 6 1,308 Nov-13-2023, 09:23 AM
Last Post: Annaat20
  get data (temperature and humidity) from DHT22 into CSV and sending them over the net apollo 0 3,844 Apr-16-2021, 07:49 PM
Last Post: apollo
  First Byte of a string is missing while receiving data over TCP Socket shahrukh1987 3 4,230 Nov-20-2019, 10:34 AM
Last Post: shahrukh1987
  sending data to second python script Cyberfly 1 3,152 Jan-29-2018, 10:09 AM
Last Post: Cyberfly
  sending data from my raspberry pi to my website mohitsangavikar 2 17,802 Sep-05-2017, 06:55 PM
Last Post: wrybread
  sending data to thread kiyoshi7 1 26,136 Apr-22-2017, 05:21 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020