forked from Karamax/PCS.2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.py
62 lines (51 loc) · 1.63 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import socket
import json
from tkinter import *
import tkinter.simpledialog
root = Tk()
def sayTest(event):
print(inputField.get())
msg = inputField.get()
sock.send(msg.encode())
textb.insert('end', '\n' + inputField.get())
inputField.delete(0, 'end')
if msg == 'exit':
root.destroy()
buffer = 1024 # Конфиг
port = 9090
addres = 'localhost'
try:
sock = socket.socket() # Соединениe
sock.connect((addres, port))
while True:
var = tkinter.simpledialog.askstring("Name prompt", "enter your name")
sock.send(var.encode()) # Логин
status = sock.recv(buffer).decode()
print(status)
if status == 'OK':
break
while True:
var = tkinter.simpledialog.askstring("Name prompt", "enter your pass")
import hmac, hashlib
var = hmac.new(bytearray('signature', 'utf-8'), bytearray(var, 'utf-8'), hashlib.sha256).hexdigest()
sock.send(var.encode()) # Пароль
status = sock.recv(buffer).decode()
print(status)
if status == 'OK':
break
print('Login and password accepted.')
msgDB = sock.recv(buffer).decode() # Получение архива сообqщений
msgDB = json.loads(msgDB)
textb = tkinter.Text(root)
textb.pack()
inputField = tkinter.Entry(root)
# self.inputField["command"] = self.sayTest
inputField.pack()
root.bind('<Return>', sayTest)
for m in msgDB:
textb.insert('end', '\n' + m)
root.mainloop()
sock.send(b'exit')
sock.close()
except Exception as e:
print('Oops, something went wrong' + e)