How can I detect the cancel request in C++ grpc?

217 Views Asked by At

I want to exchange a data with grpc.

While doing this, I am trying to establish a connection between c++ and c#. I created a server with C++. I have a client with C#. I can simply make request response examples. I want to provide continuous data flow by server streaming. However, I want to cancel the stream by sending a message from the client to stop the stream. I thought of doing this by C# using cancellationTokenSource. On the C++ side, I am trying to understand whether this cancel request came with IsCancelled, but I could not succeed. I wonder if I should send information with a different method instead of cancellationtoken from c#? How to trigger Iscancelled?

if (context->IsCancelled()) {
            //I am trying to understand cancel request in c++
            return grpc::Status(grpc::StatusCode::CANCELLED, "RPC is cancelled by the client");
        }


in C#:

 _token = new CancellationTokenSource();
using var response= client.task(request,cancellationToken: _token.Token );

 public void button() // I send Cancel request
    {
        _token.Cancel();
    }
0

There are 0 best solutions below

Related Questions in GRPC-C#