Skip to content

Instantly share code, notes, and snippets.

@fzankl
Created January 24, 2021 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzankl/8dfb2bd69c834a8139250ed5dc5b1db5 to your computer and use it in GitHub Desktop.
Save fzankl/8dfb2bd69c834a8139250ed5dc5b1db5 to your computer and use it in GitHub Desktop.
Creating a websocket connection to Azure IoT Hub device streams
public async Task<ClientWebSocket> CreateAsync(
Uri url, string authorizationToken,
CancellationToken cancellationToken)
{
var webSocketClient = new ClientWebSocket();
webSocketClient
.Options
.SetRequestHeader(
"Authorization",
$"Bearer {authorizationToken}");
await webSocketClient.ConnectAsync(
url,
cancellationToken).ConfigureAwait(false);
return webSocketClient;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment