-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
68 lines (55 loc) · 1.26 KB
/
client.py
File metadata and controls
68 lines (55 loc) · 1.26 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import socket, threading, time
key = 8194
shutdown = False
join = False
def receiving(name, sock):
while not shutdown:
try:
while True:
data, address = sock.recvfrom(1024)
#print(data.decode("utf-8"))
# Begin
decrypt = ""; k = False
for i in data.decode("utf-8"):
if i == ":":
k = True
decrypt += i
elif k == False or i == " ":
decrypt += i
else:
decrypt += chr(ord(i)^key)
print(decrypt)
# End
time.sleep(0.2)
except:
pass
host = socket.gethostbyname(socket.gethostname())
port = 0
server = (host, 9090)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((host, port))
s.setblocking(0)
alias = input("Name: ")
rT = threading.Thread(target = receiving, args = ("RecvThread", s))
rT.start()
while shutdown == False:
if join == False:
s.sendto(("[" + alias + "] => joined to chat").encode("utf-8"), server)
join = True
else:
try:
message = input()
# Begin
crypt = ""
for i in message:
crypt += chr(ord(i)^key)
message = crypt
# End
if message != "":
s.sendto(("[" + alias + "] :: " + message).encode("utf-8"), server)
time.sleep(0.2)
except:
s.sendto(("[" + alias + "] <= left chat").encode("utf-8"), server)
shutdown = True
rT.join()
s.close()