All Projects → devlooped → WebSocketPipe

devlooped / WebSocketPipe

Licence: MIT license
System.IO.Pipelines API adapter for System.Net.WebSockets

Programming Languages

C#
18002 projects
powershell
5483 projects
SCSS
7915 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to WebSocketPipe

k8s-knative-gitlab-harbor
Build container images with Knative + Gitlab + Harbor inside Kops cluster running on AWS
Stars: ✭ 23 (+35.29%)
Mutual labels:  pipelines
webfuse
websocket filesystem based on libfuse
Stars: ✭ 23 (+35.29%)
Mutual labels:  websockets
django-rest-live
Subscribe to updates from Django REST Framework over Websockets.
Stars: ✭ 48 (+182.35%)
Mutual labels:  websockets
fhq-server
This is an open source platform for competitions of computer security.
Stars: ✭ 33 (+94.12%)
Mutual labels:  websockets
NewmanPostman VSTS Task
A task for Azure DevOps Pipelines to run newman tests.
Stars: ✭ 31 (+82.35%)
Mutual labels:  pipelines
socketio-shared-webworker
Socket.io client inside a WebWorker thread
Stars: ✭ 85 (+400%)
Mutual labels:  websockets
unity-webgl-multiplayer
Unity WebGL basic multiplayer demo using WebSockets
Stars: ✭ 43 (+152.94%)
Mutual labels:  websockets
simple-websocket-server
A simple WebSocket server
Stars: ✭ 26 (+52.94%)
Mutual labels:  websockets
MAVCesium
An experimental web based map display for MAVProxy based on Cesium
Stars: ✭ 28 (+64.71%)
Mutual labels:  websockets
mojo.js
🦄 The Mojolicious real-time web framework for Node.js
Stars: ✭ 145 (+752.94%)
Mutual labels:  websockets
ng2-STOMP-Over-WebSocket
STOMP Over WebSocket service for angular2
Stars: ✭ 35 (+105.88%)
Mutual labels:  websockets
gateway.js
The gateway to Discord.
Stars: ✭ 23 (+35.29%)
Mutual labels:  websockets
play2-sockjs
A SockJS server implementation for Play Framework.
Stars: ✭ 60 (+252.94%)
Mutual labels:  websockets
general-angular
Realtime Angular Admin/CRUD Front End App
Stars: ✭ 24 (+41.18%)
Mutual labels:  websockets
Lecture2Gether
A tool for synchronized online streaming
Stars: ✭ 52 (+205.88%)
Mutual labels:  websockets
CoreRemoting
RPC library with classic .NET Remoting flavour
Stars: ✭ 23 (+35.29%)
Mutual labels:  websockets
real-time-data-viz-d3-crossfilter-websocket-tutorial
Tutorial on real-time data visualization. Python websocket server & d3.js + crossfilter.js frontend
Stars: ✭ 32 (+88.24%)
Mutual labels:  websockets
tibanna
Tibanna helps you run your genomic pipelines on Amazon cloud (AWS). It is used by the 4DN DCIC (4D Nucleome Data Coordination and Integration Center) to process data. Tibanna supports CWL/WDL (w/ docker), Snakemake (w/ conda) and custom Docker/shell command.
Stars: ✭ 61 (+258.82%)
Mutual labels:  pipelines
Geluid
Made with Electron. Streams audio from your soundcard to a browser in an easy way
Stars: ✭ 29 (+70.59%)
Mutual labels:  websockets
gee
🏵 Gee is tool of stdin to each files and stdout. It is similar to the tee command, but there are more functions for convenience. In addition, it was written as go
Stars: ✭ 65 (+282.35%)
Mutual labels:  pipelines

Icon WebSocketPipe

High-performance System.IO.Pipelines API adapter for System.Net.WebSockets

Version Downloads License Build

Usage

using Devlooped.Net;

var client = new ClientWebSocket();
await client.ConnectAsync(serverUri, CancellationToken.None);

using IWebSocketPipe pipe = WebSocketPipe.Create(client, closeWhenCompleted: true);

// Start the pipe before hooking up the processing
var run = pipe.RunAsync();

The IWebSocketPipe interface extends IDuplexPipe, exposing Input and Output properties that can be used to read incoming messages and write outgoing ones.

For example, to read incoming data and write it to the console, we could write the following code:

await ReadIncoming(pipe.Input);

async Task ReadIncoming(PipeReader reader)
{
    while (await reader.ReadAsync() is var result && !result.IsCompleted)
    {
        Console.WriteLine($"Received: {Encoding.UTF8.GetString(result.Buffer)}");
        reader.AdvanceTo(result.Buffer.End);
    }
    Console.WriteLine($"Done reading.");
}

Similarly, to write to the underlying websocket the input entered in the console, we use code like the following:

await SendOutgoing(pipe.Output);

async Task SendOutgoing(PipeWriter writer)
{
    while (Console.ReadLine() is var line && line?.Length > 0)
    {
        Encoding.UTF8.GetBytes(line, writer);
    }
    await writer.CompleteAsync();
    Console.WriteLine($"Done writing.");
}

If we wanted to simultaneously read and write and wait for completion of both operations, we could just wait for both tasks:

// Wait for completion of processing code
await Task.WhenAny(
    ReadIncoming(pipe.Input),
    SendOutgoing(pipe.Output));

Note that completing the PipeWriter automatically causes the reader to reveive a completed result and exit the loop. In addition, the overall IWebSocketPipe.RunAsync task will also run to completion.

The IWebSocketPipe takes care of gracefully closing the connection when the input or output are completed, if closeWhenCompleted is set to true when creating it.

Alternatively, it's also possible to complete the entire pipe explicitly, while setting an optional socket close status and status description for the server to act on:

await pipe.CompleteAsync(WebSocketCloseStatus.NormalClosure, "Done processing");

Specifying a close status will always close the underlying socket.

The WebSocketPipe can also be used on the server. The following example is basically taken from the documentation on WebSockets in ASP.NET Core and adapted to use a WebSocketPipe to echo messages to the client:

app.Use(async (context, next) =>
{
    if (context.Request.Path == "/ws")
    {
        if (context.WebSockets.IsWebSocketRequest)
        {
            using var websocket = await context.WebSockets.AcceptWebSocketAsync();
            using var pipe = WebSocketPipe.Create(websocket, true);
            await Task.WhenAll(Echo(pipe), pipe.RunAsync(context.RequestAborted));
        }
        else
        {
            context.Response.StatusCode = (int) HttpStatusCode.BadRequest;
        }
    }
    else
    {
        await next();
    }
});

The sample Echo method is simply:

async Task Echo(IDuplexPipe pipe)
{
    while (await pipe.Input.ReadAsync() is var result && !result.IsCompleted)
    {
        // Just assume we get a single-segment entry, for simplicity
        await pipe.Output.WriteAsync(result.Buffer.First);
        pipe.Input.AdvanceTo(result.Buffer.End);
    }
}

Dogfooding

CI Version Build

We also produce CI packages from branches and pull requests so you can dogfood builds as quickly as they are produced.

The CI feed is https://pkg.kzu.io/index.json.

The versioning scheme for packages is:

  • PR builds: 42.42.42-pr[NUMBER]
  • Branch builds: 42.42.42-[BRANCH].[COMMITS]

Sponsors

sponsored clariusclarius

get mentioned here too!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].