-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomms_client.py
41 lines (29 loc) · 1.01 KB
/
comms_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
import threading
import time
import grpc
import commspb_pb2
import commspb_pb2_grpc
def get_messages():
while True:
# message = input("Please enter a message (or nothing to stop chatting): ")
# if message == "":
# break
room = commspb_pb2.Channel(channel_id = 'test')
status = commspb_pb2.Message(channel = room, message = "Hey")
yield status
time.sleep(1)
def __listen_for_messages(stub, room):
for message in stub.JoinChannel(room):
print(room + ": " + message)
def run():
with grpc.insecure_channel('0.0.0.0:5400') as channel:
stub = commspb_pb2_grpc.CommsServiceStub(channel)
room = commspb_pb2.Channel(channel_id = 'test')
threading.Thread(target=__listen_for_messages, args=(stub, room)).start()
# for message in response:
# print(message)
# print(status)
# stub.SendMessage(get_messages())
# response.listen(print)
if __name__ == "__main__":
run()