Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 26, 2020 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/75f6f2f53e722db2a7343c03782a74aa to your computer and use it in GitHub Desktop.
Save velotiotech/75f6f2f53e722db2a7343c03782a74aa to your computer and use it in GitHub Desktop.
import grpc
import unary.unary_pb2_grpc as pb2_grpc
import unary.unary_pb2 as pb2
class UnaryClient(object):
"""
Client for gRPC functionality
"""
def __init__(self):
self.host = 'localhost'
self.server_port = 50051
# instantiate a channel
self.channel = grpc.insecure_channel(
'{}:{}'.format(self.host, self.server_port))
# bind the client and the server
self.stub = pb2_grpc.UnaryStub(self.channel)
def get_url(self, message):
"""
Client function to call the rpc for GetServerResponse
"""
message = pb2.Message(message=message)
print(f'{message}')
return self.stub.GetServerResponse(message)
if __name__ == '__main__':
client = UnaryClient()
result = client.get_url(message="Hello Server you there?")
print(f'{result}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment