-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
27 lines (24 loc) · 887 Bytes
/
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
import grpc
import sys
import gossip_pb2, gossip_pb2_grpc
from peers import Peers
def run(node_id, action):
peer_target = Peers.get_peer_target(node_id)
with grpc.insecure_channel(peer_target) as channel:
stub = gossip_pb2_grpc.GossipServiceStub(channel)
if action == "increment":
response = stub.Increment(gossip_pb2.GossipMessage())
print("Increment success:", response.success)
elif action == "getCount":
response = stub.GetGossipCount(gossip_pb2.GossipMessage())
print("Gossip count:", response.count)
else:
print("Invalid action:", action)
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python client.py <node_id> <action>")
sys.exit(1)
node_id = int(sys.argv[1])
action = sys.argv[2]
run(node_id, action)