SHARE:

.NET 10: Streaming over WebSockets with the New WebSocket Stream API

Introduction

.NET 10 introduces a new WebSocket stream API that makes working with WebSockets feel much more like working with regular .NET streams.

Instead of manually handling frames and buffers, you can now stream data directly over a WebSocket using familiar Stream APIs.

Why this matters

WebSockets are often used for:

  • Large file uploads or downloads
  • Real-time data feeds
  • Continuous bidirectional communication

Until now, streaming large payloads required custom loops and message framing. .NET 10 simplifies this by exposing WebSockets as a Stream.

Exemple

Below is a client-side example that streams a large file directly over a WebSocket connection:

This works exactly like copying data between two file streams, except the destination is a WebSocket.

Conclusion

The new WebSocket stream API in .NET 10 significantly lowers the complexity of streaming data over WebSockets. If you’re already comfortable with Stream, you already know how to use it.

Simple, idiomatic, and efficient, exactly how networking APIs should feel in modern .NET.

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.