-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
37 lines (27 loc) · 1.04 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
import datetime
import grpc
import threading
from time import sleep
from push_mode import SubmitRequest, MessageSyncStub, ConnRequest, LogInRequest, HistoryRequest
def listen(client):
while True:
response = client.PushMessageStream(ConnRequest())
for r in response:
print(r.message)
def run():
conn = grpc.insecure_channel("localhost:8080")
client = MessageSyncStub(channel=conn)
thread = threading.Thread(target=listen, args=(client,))
thread.start()
name = input("Введите ваше имя: ")
response = client.LogIn(LogInRequest(name=name))
print(response.reply)
print(client.GetHistory(HistoryRequest(name=name)).message)
while True:
header = input("Bведите заголовок: ")
msg = input("Введите сообщение: ")
curr_time = datetime.datetime.now().strftime("%d-%m-%y %H:%M")
client.SubmitMessage(SubmitRequest(name=name, header=header, message=msg, time=curr_time))
sleep(0.1)
if __name__ == '__main__':
run()