RPC de streaming: del servidor, del cliente y bidireccional
Vaya más allá de las llamadas unarias y aprenda los tres modos de streaming de gRPC para enviar secuencias de mensajes en una sola llamada.
RPC de streaming: del servidor, del cliente y bidireccional es una lección gratuita de gRPC & High Performance APIs en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de gRPC & High Performance APIs, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de gRPC & High Performance APIs incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Beyond Unary
A unary RPC is one request, one response. But many problems need a sequence of messages — feeds, uploads, chat.
gRPC offers three streaming modes built on HTTP/2 streams.
The Four Method Shapes
In a .proto service you can declare:
- Unary: one in, one out.
- Server streaming: one in, many out.
- Client streaming: many in, one out.
- Bidirectional: many in, many out.
Declaring Streams in Proto
The stream keyword marks a parameter as a stream.
service Feed {
rpc Watch (WatchRequest) returns (stream Event);
rpc Upload (stream Chunk) returns (UploadResult);
rpc Chat (stream Message) returns (stream Message);
}Server Streaming
The client sends one request; the server replies with many messages until it closes the stream.
Great for: live feeds, large result sets, progress updates.
// Server side (Go-style pseudocode)
func (s *server) Watch(req *WatchRequest, stream Feed_WatchServer) error {
for _, e := range events {
stream.Send(e)
}
return nil
}Client Streaming
The client sends many messages, then the server returns a single response.
Great for: file uploads, batched ingestion, aggregations.
// Server reads the whole client stream, then replies once
func (s *server) Upload(stream Feed_UploadServer) error {
for {
chunk, err := stream.Recv()
if err == io.EOF {
return stream.SendAndClose(&UploadResult{})
}
}
}Bidirectional Streaming
Both sides send streams independently over the same call. Messages can interleave freely.
Great for: chat, real-time collaboration, interactive protocols.
Why It's Efficient
All four shapes ride a single HTTP/2 stream — no new connection per message.
Multiplexing means many streaming calls share one connection without head-of-line blocking.
Flow Control
HTTP/2 provides built-in flow control, so a slow reader naturally backpressures a fast writer.
This prevents a streaming server from overwhelming a client that can't keep up.
Ending a Stream
Streams close explicitly:
- Server streaming ends when the server returns.
- Client streaming ends when the client signals end-of-stream and the server replies.
- Bidirectional ends when both halves complete or an error/cancel occurs.
Errors & Cancellation
Either side can cancel or fail mid-stream. The peer receives a status code and should clean up.
Always handle EOF and error returns from Recv() / Send() to avoid leaks.
Choosing a Mode
Pick by data shape:
- One-shot request/response: unary.
- Push many results: server streaming.
- Send many, get a summary: client streaming.
- Continuous two-way: bidirectional.
Quick Check
Test your understanding of streaming RPCs.
Recap
You learned gRPC's streaming modes.
- Unary, server streaming, client streaming, and bidirectional.
- Mark streams with the
streamkeyword in proto. - All ride a single multiplexed HTTP/2 stream with built-in flow control.
- Choose the mode that matches your data's shape.
Preguntas frecuentes
¿La lección «RPC de streaming: del servidor, del cliente y bidireccional» es gratis?
Sí — el texto completo de «RPC de streaming: del servidor, del cliente y bidireccional» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de gRPC & High Performance APIs, actualiza a CoddyKit PRO. El curso de gRPC & High Performance APIs incluye 4 lecciones en total.
¿Qué aprenderé en «RPC de streaming: del servidor, del cliente y bidireccional»?
Vaya más allá de las llamadas unarias y aprenda los tres modos de streaming de gRPC para enviar secuencias de mensajes en una sola llamada. Practicas gRPC & High Performance APIs con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar gRPC & High Performance APIs?
No se requiere experiencia previa. gRPC & High Performance APIs en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «RPC de streaming: del servidor, del cliente y bidireccional»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de gRPC & High Performance APIs?
Sí. Cada lección de gRPC & High Performance APIs incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Definición de esquemas Protobuf
- Generación de código gRPC
- Servicio gRPC unario sencillo
- RPC de streaming: del servidor, del cliente y bidireccional