Skip to content

Instantly share code, notes, and snippets.

@AnthonyGiretti
Created January 7, 2026 20:18
Show Gist options
  • Select an option

  • Save AnthonyGiretti/aa9235bae1202ae496a59efae34f9f45 to your computer and use it in GitHub Desktop.

Select an option

Save AnthonyGiretti/aa9235bae1202ae496a59efae34f9f45 to your computer and use it in GitHub Desktop.
.NET 10 new WebSocketStream API
using System.Net.WebSockets;
using System.IO;
// Client side, streaming supported over WebSockets
var client = new ClientWebSocket();
await client.ConnectAsync(new Uri("wss://example.com/upload"), CancellationToken.None);
using var wsStream = WebSocketStream.Create(client);
await using var fileStream = File.OpenRead("bigfile.zip");
// Copy file to WebSocket stream
await fileStream.CopyToAsync(wsStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment