-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientside.py
54 lines (46 loc) · 1.56 KB
/
clientside.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import socket
import threading
from colorama import Fore,Style
print(Fore.LIGHTMAGENTA_EX+"""
へ
૮ - ՛ つ ClientSide
/ ⁻៸ (˚ˎ 。7
乀 (ˍ, ل |、˜〵
▀▀▀▀▀▀▀▀▀▀▀▀ じしˍ,) ノ
"""+Style.RESET_ALL)
nickname = input(Fore.LIGHTBLUE_EX+'Enter your nickname: '+Style.RESET_ALL)
host = input(Fore.LIGHTMAGENTA_EX+"server ip > "+Style.RESET_ALL)
port = input(Fore.LIGHTMAGENTA_EX+"port number > "+Style.RESET_ALL)
os.system("cls")
ask = input(Fore.LIGHTBLUE_EX+"are u sure the address are right?\n server ip : "+host+" \n port number: "+port+"\n(yes\\no) >"+Style.RESET_ALL)
if ask.lower() =="yes":
pass
else:
ask.lower()=="no"
print("quit!")
quit()
port = int(port)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((host, port))
def receive():
while True:
try:
message = client.recv(1024).decode('ascii')
if message == 'nick':
client.send(nickname.encode('ascii'))
else:
print(message)
except:
print('Error')
client.close()
break
def write():
while True:
print(Fore.LIGHTBLUE_EX)
message = f'{Fore.LIGHTMAGENTA_EX+nickname+Fore.LIGHTBLUE_EX}: {input(" > ")}'
client.send(message.encode('ascii'))
receive_thread = threading.Thread(target=receive)
receive_thread.start()
write_thread = threading.Thread(target=write)
write_thread.start()