-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
34 lines (28 loc) · 816 Bytes
/
client.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
import socket
import threading
nickname = input("choose a nickname: ")
HOST = '127.0.0.1'
PORT = 6969
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST , PORT))
def recive():
while True:
try:
message = client.recv(1024).decode('ascii')
if message == 'NICK':
client.send(nickname.encode('ascii'))
else:
print(message)
except:
print("connection has been closed")
client.close()
break
def write():
while True:
message = f'{nickname}: {input("")}'
client.send(message.encode('ascii'))
recieve_thread = threading.Thread(target=recive)
recieve_thread.start()
write_thread = threading.Thread(target=write )
write_thread.start()
client.close()