Newbie Question: Do I need to start GRPC server in own thread?

52 views
Skip to first unread message

maxwel...@gmail.com

unread,
Mar 12, 2019, 6:15:09 AM3/12/19
to grpc.io
Hi,

I have a machine control program which is written in c++. I want this program to also have a grpc server, so that one can remotely check the status of the machine. I followed the tutorial and start the server like this:

  builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
  builder.RegisterService(&service);
  std::unique_ptr<Server> server(builder.BuildAndStart());
  server->Wait();

the wait() seems to be blocking, so my machine user interface does not continue. Does this mean I need to start the grpc server in its own thread?

Best regards,
Maxwell

Christian Rivasseau

unread,
Mar 12, 2019, 6:18:39 AM3/12/19
to maxwel...@gmail.com, grpc.io
Or don't call Wait() ?

--
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 grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/fccddebc-0bbd-4d0d-a9b0-eaa14d9a30d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Christian Rivasseau
Co-founder and CTO @ Lefty
+33 6 67 35 26 74

maxwel...@gmail.com

unread,
Mar 12, 2019, 6:22:26 AM3/12/19
to grpc.io
Ah, so the server is also running if I dont call wait?

Christopher Warrington - MSFT

unread,
Mar 12, 2019, 8:28:39 PM3/12/19
to grpc.io
On Tuesday, March 12, 2019 at 3:22:26 AM UTC-7, maxwel...@gmail.com wrote:
> Ah, so the server is also running if I dont call wait?

Yes. Among other things, BuildAndStart() starts listenting for requests.

Wait() is using during shutdown typically. Here's an excerpt from the
documentation for Wait() [1] that :

> Block waiting for all work to complete.
>
> Warning
>
> The server must be either shutting down or some other thread must call
> Shutdown for this function to ever return.

[1]: https://grpc.io/grpc/cpp/classgrpc_1_1_server_interface.html#ac36477b6a7593a4e4608c7eb712b0d70

--
Christopher Warrington
Microsoft Corp.
Reply all
Reply to author
Forward
0 new messages