title: GRPC/C++ - Server reads only the first message from the bidi stream
body: <p>I am using gRPC with C++. And I have an async server and sync client. The rpc is of type bidirectional stream.</p>
  <p>Here is how I send message with client:</p>
  <pre><code>class ConnectionService {
  public:
      ConnectionService(std::shared_ptr&lt;Channel&gt; channel)
              : stub_(Connection::NewStub(channel)) {}
  
      void HearthBeat() {
          ClientContext context;
  
          std::shared_ptr&lt;grpc::ClientReaderWriter&lt;Pulse, Pulse&gt; &gt; stream(
                  stub_-&gt;HearthBeat(&amp;context));
  
          std::thread writer([stream]() {
              for (int i = 0; i &lt; 100; ++i) {
                  Pulse p;
                  p.set_rate(50);
                  stream-&gt;Write(p);
              }
              stream-&gt;WritesDone();
          });
  
          Pulse server_pulse;
          while (stream-&gt;Read(&amp;server_pulse)) {
              std::cout &lt;&lt; &quot;Got message &quot; &lt;&lt; server_pulse.rate()&lt;&lt; std::endl;
          }
          writer.join();
          Status status = stream-&gt;Finish();
          if (!status.ok()) {
              std::cout &lt;&lt; &quot;RouteChat rpc failed.&quot; &lt;&lt; std::endl;
          }
      }
  
  private:
      std::unique_ptr&lt;Connection::Stub&gt; stub_;
  };
  </code></pre>
  <p>Here is how I read it and reply on the server:</p>
  <pre><code>void Vibranium::ConnectionManager::HearthBeatMethod::Create() {
      connectionService_-&gt;RequestHearthBeat(&amp;ctx_, &amp;stream_, cq_, cq_,this);
      status_ = PROCESS;
  }
  
  void Vibranium::ConnectionManager::HearthBeatMethod::Process() {
      new HearthBeatMethod(connectionService_, cq_);
      stream_.Read(&amp;request_, this);
      status_ = READ_CALLED;
  }
  
  bool Vibranium::ConnectionManager::HearthBeatMethod::CheckForClientMetadata() {
      return false;
  }
  
  void Vibranium::ConnectionManager::HearthBeatMethod::ReadStream() {
      std::cout &lt;&lt; &quot;Received: &quot; &lt;&lt; request_.rate() &lt;&lt; std::endl;
      reply_.set_rate(65);
      std::cout &lt;&lt; &quot;Rate replied: &quot; &lt;&lt; reply_.rate() &lt;&lt; std::endl;
      stream_.Write(reply_, this);
      status_ = WRITE_CALLED;
  }
  
  void Vibranium::ConnectionManager::HearthBeatMethod::WriteToStream() {
      stream_.Finish(grpc::Status::OK, this);
      status_ = FINISH;
  }
  </code></pre>
  <p>Here is how I start the server:</p>
  <pre><code>void Vibranium::Server::Run() {
      std::string server_address(serverIp_+&quot;:&quot;+serverPort_);
  
      grpc::ServerBuilder builder;
      // Listen on the given address without any authentication mechanism.
      builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_TIME_MS, 3000);
      builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 3000);
      builder.AddChannelArgument(GRPC_ARG_HTTP2_BDP_PROBE, 1);
      builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1);
      builder.AddChannelArgument(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS, 1000);
      builder.AddChannelArgument(GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS, 3000);
      builder.AddChannelArgument(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0);
      builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
      RegisterServices(builder);
      cq_ = builder.AddCompletionQueue();
      // Finally assemble the server.
      server_ = builder.BuildAndStart();
      std::cout &lt;&lt; &quot;Server listening on &quot; &lt;&lt; server_address &lt;&lt; std::endl;
  
      // Proceed to the server's main loop.
      HandleRpcs();
  }
  
  void Vibranium::Server::HandleRpcs() {
      RegisterMethods();
      void* tag;  // uniquely identifies a request.
      bool ok;
      while (true) {
          GPR_ASSERT(cq_-&gt;Next(&amp;tag, &amp;ok));
          GPR_ASSERT(ok);
          static_cast&lt;ServiceMethod*&gt;(tag)-&gt;Proceed();
      }
  }
  </code></pre>
  <p>Here is what <code>Proceed();</code> is doing:</p>
  <pre><code>void ServiceMethod::Proceed() {
      if (status_ == CREATE) {
          Create();
      } else if (status_ == PROCESS) {
          CheckClient();
          Process();
      } else if(status_ == READ_CALLED){
          ReadStream();
      } else if(status_ == WRITE_CALLED){
          WriteToStream();
      } else {
          Finish();
      }
  }
  
  void ServiceMethod::Finish() {
      GPR_ASSERT(status_ == FINISH);
      // Once in the FINISH state, deallocate ourselves (ServiceMethod).
      delete this;
  }
  </code></pre>
  <p>So when I trigger the client it sends 1 message instead of 100 as described in the for loop.
  On server I can see output:</p>
  <pre><code>Received: 50
  Rate replied: 65
  </code></pre>
  <p>And on client the output is:</p>
  <pre><code>Got message 65
  </code></pre>
  <p>So by this I can see that there is communication between the client and the server however it seems that the server receives and send back just the fist message. Why is that and how can I fix it?</p>