Files
live-campus-mcs-p-2027.2/Semaine_09/Socket_chat/client_correction.py
T
gauvainboiche ce1f0e513a feat: Semaine 9
2026-05-15 16:24:56 +02:00

24 lines
596 B
Python

#client
import socket
import threading
from utils import receive_messages, send_messages
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 9999))
pseudo = input("Choisissez votre pseudo : ")
client_socket.send(pseudo.encode())
print(f"Connecté au chat en tant que {pseudo} !\n")
thread_recv = threading.Thread(target=receive_messages, args=(client_socket,))
thread_send = threading.Thread(target=send_messages, args=(client_socket,))
thread_recv.start()
thread_send.start()
thread_recv.join()
thread_send.join()
print("Chat terminé.")