Bidirectional streaming

Chat Service

Both sides stream messages independently and at the same time, like a live chat room.

many ↔ many, at once

1. The contract

This is real gRPC code. It defines the service and messages.
chat.proto
syntax = "proto3";

package demo;

// BIDIRECTIONAL STREAMING: streams both ways at once
service Chat {
  rpc Connect (stream ChatMessage) returns (stream ChatMessage);
}

message ChatMessage {
  string user = 1;
  string text = 2;
  string time = 3;
}

2. Live simulation

Watch how messages flow for this pattern.

// Press the button to start the Bidirectional streaming demo.