On Fri, Jul 29, 2016 at 5:24 AM, Mosca, Federico <[email protected]>
wrote:
> Hi, so do you suggest to do this:
>
> client.py
>
> *import *grpc
> *import *generated.bidirectional_pb2 *as *bid
>
>
>
> *def *run():
> channel = grpc.insecure_channel(*'localhost:50051'*)
> stub = bid.SpeakStub(channel)
>
Constructing a channel and a stub aren't enough to exchange messages; you
must also invoke an RPC. From your .proto like the way to do that will be
to add "my_response_iterator = stub.Message(<your iterator of request
messages>)" to this client-side code (and then additional code doing
whatever it is that you want to do with the responses that you receive). If
you don't need to ever send any request messages, something like "iter(())"
would be fine for <your iterator of request messages>.
*if *__name__ == *'__main__'*:
> run()
>
>
>
> server.py
>
> *def *serve():
> server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
> bid.add_SpeakServicer_to_server(bid.SpeakServicer(),server)
> server.add_insecure_port(*'[::]:50051'*)
> server.start()
> *print *
> *"[SERVER] start at 50051" **try*:
> *while *True:
> time.sleep(_ONE_DAY_IN_SECONDS)
> *except *KeyboardInterrupt:
> server.stop(0)
>
> *if *__name__ == *'__main__'*:
> serve()
>
>
>
> but I don’t get where I should implement the servicer
> SpeakServicer(bid.BetaSpeakServicer) and how to invoke it for be that the
> server send the message to the client.
>
> bidirectional_pb2.SpeakServicer is a do-nothing class that has an
implementation of the Message method that raises NotImplementedError
(right?). What we intend is for you to subclass
bidirectional_pb2.SpeakServicer and override its implementation of the
Message method with an implementation that does whatever you wish it to do.
Then rather than instantiating bidirectional_pb2.SpeakServicer and passing
that object to add_SpeakServicer_to_server, pass an instance of your
subclass to add_SpeakServicer_to_server.
> Where the proto file is
>
> service Speak {
>
> rpc Message(stream Request) returns (stream Response){}
>
> }
>
> Can you help me?
>
> I hope I have; please feel welcome to ask more!
-Nathaniel
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/CAEOYnAQW4XX-rThW0rfsV8kfo5U%3DcoiRVr3PW-9Ug8YHcGm8Gw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.