0

Client.py:

import socket, time

SERVER = '0.0.0.0'
PORT = 433

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


def connect():
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client.connect(ADDR)
    # message = client.recv(1024).decode()
    # print(message)
    return client

# Print the received message

def send(client, msg):
    message = msg.encode(FORMAT)
    client.send(message)


def start():
    connection = connect()
    f=input('Press Enter to start....')
    print(f)
    while True:
        msg = input("Message (q for quit): ")

        if msg == 'q':
            break

        send(connection, msg)
        msg2 = connection.recv(1024).decode(FORMAT)
        print(msg2)

    send(connection, DISCONNECT_MESSAGE)
    time.sleep(2)
    print('Disconnected')


start()

Everytime a message is sent on a client I have to enter a message to get other messages sent by other clients, i want it to automatically update though like print up input down? maybe using like asyncio or threading?

0 Answers0