37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import socket
|
|
import threading
|
|
from env_var import SERVER_PORT, CLIENT_PORT
|
|
|
|
from utils import receive_messages, send_messages
|
|
|
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
client.connect(("localhost", SERVER_PORT))
|
|
|
|
client_username = input("Rentrez votre pseudonyme (min 3 et max 12 caractères) pour la session > ")
|
|
|
|
if len(client_username) < 3 \
|
|
or len(client_username) > 12:
|
|
print(f"{client_username} contient {len(client_username)} caractères et n'est donc pas valide. Recommencez.")
|
|
quit(1)
|
|
|
|
print(f"Bienvenue, {client_username}.")
|
|
print("🤝 Clavardage démarré. Tapez vos messages à la suite. Tapez 'QUIT' ou 'Q' pour quitter.")
|
|
print()
|
|
|
|
client.sendall(f"USERNAME >>> {client_username}".encode("utf-8"))
|
|
|
|
thread_recv = threading.Thread(target=receive_messages, args=(client,))
|
|
thread_send = threading.Thread(target=send_messages, args=(client, client_username))
|
|
|
|
thread_recv.daemon = False
|
|
thread_send.daemon = True
|
|
|
|
thread_recv.start()
|
|
thread_send.start()
|
|
|
|
thread_recv.join()
|
|
thread_send.join()
|
|
|
|
client.close()
|
|
print("❌ Connexion fermée.")
|