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
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