-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
44 lines (35 loc) · 1.14 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
import socket
import threading
import encrypte
nickname = input("Choose your nickname: ")
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 55555))
def receive():
while True:
try:
message = client.recv(1024).decode('ascii')
if ": " in message:
message_dec = encrypte.caesar_dec(message.split(": ")[1],N)
name = message.split(": ")[0]
message = name+": "+message_dec
if message == 'NICK':
client.send(nickname.encode('ascii'))
else:
print(message)
except:
print("An error occured!")
client.close()
break
text = "ATTACKATONCE"
s = 4
#Number of shifting
N=3
# Sending Messages To Server
def write():
while True:
message = '{}: {}'.format(nickname, encrypte.caesar_enc(input(''),N))
client.send(message.encode('ascii'))
receive_thread = threading.Thread(target=receive)
receive_thread.start()
write_thread = threading.Thread(target=write)
write_thread.start()