Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
2
Indexable
Never
import socket
import threading
try:
  from colorama import Fore, Back, Style, init
except ModuleNotFoundError:
  import os
  os.system("pip install colorama")
from colorama import Fore, Back, Style, init

nickname = input(Fore.RED + "Kullanıcı İsmi: " + Fore.CYAN)                                                                                             init(autoreset = True)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("5.tcp.eu.ngrok.io", 10450))
def receive():
    while True:
        try:
            message = client.recv(1024).decode()
            if message == 'NICK':
                client.send(nickname.encode())
            else:
                print(message)
        except:
            print("Hata!")
            client.close()
            break
def write():
    while True:
        mess = input('\033[1A' + '' + '\033[K')
        message = '{red}{nickname}: {green}{mess}'.format(red = Fore.RED, nickname=nickname,green = Fore.GREEN, mess = mess)
        client.send(message.encode())

receive_thread = threading.Thread(target=receive)
receive_thread.start()

write_thread = threading.Thread(target=write)
write_thread.start()