Created
June 26, 2020 12:17
-
-
Save velotiotech/ad7b026cad3b523de876cf131d52d4d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import grpc | |
import bidirectional.bidirectional_pb2_grpc as bidirectional_pb2_grpc | |
import bidirectional.bidirectional_pb2 as bidirectional_pb2 | |
def make_message(message): | |
return bidirectional_pb2.Message( | |
message=message | |
) | |
def generate_messages(): | |
messages = [ | |
make_message("First message"), | |
make_message("Second message"), | |
make_message("Third message"), | |
make_message("Fourth message"), | |
make_message("Fifth message"), | |
] | |
for msg in messages: | |
print("Hello Server Sending you the %s" % msg.message) | |
yield msg | |
def send_message(stub): | |
responses = stub.GetServerResponse(generate_messages()) | |
for response in responses: | |
print("Hello from the server received your %s" % response.message) | |
def run(): | |
with grpc.insecure_channel('localhost:50051') as channel: | |
stub = bidirectional_pb2_grpc.BidirectionalStub(channel) | |
send_message(stub) | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment