Hi there,
The Read function just initiates the read; it doesn't complete until a
later Next gets called and returns that tag. You can't use the result in
feature until the later Next.


On Thu, Mar 16, 2017 at 10:47 AM 'Julien' via grpc.io <
[email protected]> wrote:

> Hello,
>
> I am trying to use the async stream in a C++ client.
>
> I made some trials by modifying the route_guide example, with the
> ListFeatures rpc method from the RouteGuide service.
>
> In the provided client, the ListFeatures() method is called with the sync
> interface. So I tried to call it with the *async *interface.
> I have thus changed the ListFeatures() function from the
> route_guide_client.cc file as follow:
>
>   void ListFeatures() {
>     routeguide::Rectangle rect;
>     Feature feature;
>     ClientContext context;
>
>     rect.mutable_lo()->set_latitude(400000000);
>     rect.mutable_lo()->set_longitude(-750000000);
>     rect.mutable_hi()->set_latitude(420000000);
>     rect.mutable_hi()->set_longitude(-730000000);
>     std::cout << "Looking for features between 40, -75 and 42, -73"
>               << std::endl;
>
>     CompletionQueue cq;
>     std::unique_ptr<ClientAsyncReader<Feature> > reader(stub_->
> AsyncListFeatures(&context, rect,&cq,(void*)1));
>     void* got_tag;
>     bool ok;
>     while (1) {
>       ok = false;
>       bool ret = cq.Next(&got_tag, &ok);
>       if (!ret || !ok) {
>         break;
>       }
>       reader->Read(&feature,got_tag);
>       if (got_tag == (void*)1) {
>         std::cout << "Found feature called "
>                 << feature.name() << " at "
>                 << feature.location().latitude()/kCoordFactor_ << ", "
>                 << feature.location().longitude()/kCoordFactor_ << std::
> endl;
>       }
>     }
>   }
>
> Unfortunately, this does not exactly work properly.
> Strangely, the client receives an additionnal Feature objet at the
> beginning of the stream. Here is the relevant part of the output of the
> client:
> -------------- ListFeatures --------------
> Looking for features between 40, -75 and 42, -73
> *Found feature called  at 0, 0*         * <---------- empty feature*
> Found feature called PatriotsPath,Mendham,NJ07945,USA at 40.7838, -74.6144
> Found feature called 101NewJersey10,Whippany,NJ07981,USA at 40.8123,
> -74.3999
> Found feature called U.S.6,Shohola,PA18458,USA at 41.3628, -74.9016
> ...
>
> This empty feature is not received with the original sync client.
>
> So what am I doing wrong in my above code?
>
> Note: I use grpc 1.1.4 and protobuf 3.2.0.
>
> Thank you in advance for your help.
>
> Julien
>
> --
> 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].
> 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/3c73c2fa-a8d7-49a7-9e1a-f9187aa8b465%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/3c73c2fa-a8d7-49a7-9e1a-f9187aa8b465%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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].
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/CADEy0h3%3DCb-8Fo_fd90emeEHsWc1%2B-8W-FvEDeW0z3cYfeDiJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to