All Projects → Spreads → Signalw

Spreads / Signalw

Licence: other
Even simpler and faster real-time web for ASP.NET Core.

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Signalw

Graphql Ws
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Stars: ✭ 398 (+218.4%)
Mutual labels:  server, websockets, transport
ChatService
ChatService (SignalR).
Stars: ✭ 26 (-79.2%)
Mutual labels:  real-time, dotnetcore, signalr
Azure Signalr
Azure SignalR Service SDK for .NET
Stars: ✭ 137 (+9.6%)
Mutual labels:  websockets, real-time, signalr
Sio.core
✔ [ SIOC ] Swastika I/O Core is an all in one platform (e.g CMS, eCommerce, Forum, Q&A, CRM...) ASP.NET Core / Dotnet Core System based on SIOH Framework.
Stars: ✭ 121 (-3.2%)
Mutual labels:  asp, signalr, dotnetcore
Signalr
Incredibly simple real-time web for .NET
Stars: ✭ 8,532 (+6725.6%)
Mutual labels:  asp, signalr
Gophergameserver
🏆 Feature packed, easy-to-use game server API for Go back-ends and Javascript clients. Tutorials and examples included!
Stars: ✭ 61 (-51.2%)
Mutual labels:  server, real-time
Sgf
This is a Smart Game Foundation (Not Framework)
Stars: ✭ 122 (-2.4%)
Mutual labels:  rpc, server
Swindon
An HTTP edge (frontend) server with smart websockets support
Stars: ✭ 87 (-30.4%)
Mutual labels:  server, websockets
Kuzzle
Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
Stars: ✭ 991 (+692.8%)
Mutual labels:  websockets, real-time
Sec Api
sec.gov EDGAR API | search & filter SEC filings | over 150 form types supported | 10-Q, 10-K, 8, 4, 13, S-11, ... | insider trading
Stars: ✭ 71 (-43.2%)
Mutual labels:  websockets, real-time
Wsrpc
node.js/browser protobuf rpc over binary websockets
Stars: ✭ 91 (-27.2%)
Mutual labels:  rpc, websockets
Rnl
RNL - Realtime Network Library - The opensource reliable UDP network library
Stars: ✭ 59 (-52.8%)
Mutual labels:  server, real-time
Subscriptions Transport Sse
A Server-Side-Events (SSE) client + server for GraphQL subscriptions
Stars: ✭ 55 (-56%)
Mutual labels:  server, transport
Socketcluster Server
Minimal server module for SocketCluster
Stars: ✭ 70 (-44%)
Mutual labels:  server, websockets
Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (+705.6%)
Mutual labels:  websockets, dotnetcore
Rtptools
RTP Tools
Stars: ✭ 74 (-40.8%)
Mutual labels:  real-time, transport
Sandstone
PHP microframework designed to build a RestApi working together with a websocket server. Build a real time RestApi!
Stars: ✭ 98 (-21.6%)
Mutual labels:  websockets, real-time
Autobahn Js
WAMP in JavaScript for Browsers and NodeJS
Stars: ✭ 1,345 (+976%)
Mutual labels:  rpc, real-time
Simpletcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 99 (-20.8%)
Mutual labels:  rpc, server
Stl.fusion
Get real-time UI updates in Blazor apps and 10-1000x faster API responses with a novel approach to distributed reactive computing. Fusion brings computed observables and automatic dependency tracking from Knockout.js/MobX/Vue to the next level by enabling a single dependency graph span multiple servers and clients, including Blazor apps running in browser.
Stars: ✭ 858 (+586.4%)
Mutual labels:  websockets, real-time

SignalW (not maintained)

Even simpler and faster real-time web for ASP.NET Core.

SignalW is a simplified version of SignalR, with only WebSockets as a transport and MemoryStream as a message type.

  • WebSockets work almost everywhere to bother about long polling/SSE/any other transport.
  • Since messages could be framed, we cannot use a single buffer and need a stream to collect all chunks. We use RecyclableMemoryStream that pools internal buffers.
  • Serialization is out of scope. It is always a pain to abstract it for a general case, but in every concrete case it could be as simple as using JSON.NET (with extension methods for streams) or as flexible as a custom binary encoding.
  • Any generic WebSocket client should work. The SignalW.Client project has a WsChannel class that wraps around the standard WebSocket class and gives methods to work with MemoryStreams instead of ArraySegments.

Instead of multiple methods inside Hubs that clients invoked by name, in SignalW we have a single method async Task OnReceiveAsync(MemoryStream payload). If one uses Angular2 with @ngrx/store then a deserialized-to-JSON message will always have a type field, and one could use a custom JsonCreationConverter<IMessage> to deserialize a message to its correct .NET type. Then one could write multiple methods with the same name that differ only by its parameter type and use dynamic keyword to dispatch a message to a correct handler.

public class DispatchHub : Hub {
    public override async Task OnReceiveAsync(MemoryStream payload) {
        // Extension method ReadJsonMessage returns IMessage object instance based on the `type` field in JSON
		object message = payload.ReadJsonMessage();
        // dispose as soon as it is no longer used becasue it uses pooled buffers inside
        payload.Dispose();

        // dynamic will dispatch to the correct method
        dynamic dynMessage = message;
        await OnReceiveAsync(dynMessage);
    }

    public async void OnReceiveAsync(MessageFoo message) {
		var stream = message.WriteJson();
        await Clients.Group("foo").InvokeAsync(stream);
    }

    public async void OnReceiveAsync(MessageBar message) {
		var stream = message.WriteJson();
        await Clients.Group("bar").InvokeAsync(stream);
    }
}

On the Angular side, one could simply use a WebSocketSubject and forward messages to @ngrx/store directly if they have a type field. No dependencies, no custom deserialization, no hassle!

Authentication with a bearer token

From a C# client

var client = new ClientWebSocket();
var header = new AuthenticationHeaderValue("Bearer", _accessToken);
client.Options.RequestHeaders.Add("Authorization", header.ToString());

From JavaScript:

It is impossible to add headers to WebSocket constructor in JavaScript, but we could use protocol parameters for this. Here we are using RxJS WebSocketSubject:

import { WebSocketSubjectConfig, WebSocketSubject } from 'rxjs/observable/dom/WebSocketSubject';
...
let wsConfig: WebSocketSubjectConfig = {
    url: 'wss://example.com/api/signalw/chat',
    protocol: [
    'access_token',
    token
    ]
};
let ws = new WebSocketSubject<any>(wsConfig);

Then in the very beginning of OWIN pipeline (before any identity middleware) use this trick to populate the correct header:

app.Use((context, next) => {
    if (!context.Request.Headers.ContainsKey("Authorization")
        && context.Request.Headers.ContainsKey("Upgrade")) {
        if (context.WebSockets.WebSocketRequestedProtocols.Count >= 2) {
            var first = context.WebSockets.WebSocketRequestedProtocols[0];
            var second = context.WebSockets.WebSocketRequestedProtocols[1];
            if (first == "access_token") {
                context.Request.Headers.Add("Authorization", "Bearer " + second);
                context.Response.Headers.Add("Sec-WebSocket-Protocol", "access_token");
            }
        }
    }
    return next();
});

To use SignalW, create a custom Hub:

[Authorize]
public class Chat : Hub {
    public override Task OnConnectedAsync() {
        if (!Context.User.Identity.IsAuthenticated) {
            Context.Connection.Channel.TryComplete();
        }
        return Task.FromResult(0);
    }

    public override Task OnDisconnectedAsync() {
        return Task.FromResult(0);
    }

    public override async Task OnReceiveAsync(MemoryStream payload) {
        await Clients.All.InvokeAsync(payload);
    }
}

Then add SignalW to the OWIN pipeline and map hubs to a path. Here we use SignalR together with MVC on the "/api" path:

public void ConfigureServices(IServiceCollection services) {
	...
	services.AddSignalW();
	...
}

public void Configure(IApplicationBuilder app, ...){
	...
	app.Map("/api/signalw", signalw => {
		signalw.UseSignalW((config) => {
			config.MapHub<Chat>("chat", Format.Text);
		});
	});
	app.Map("/api", apiApp => {
		apiApp.UseMvc();
	});
	...
}

Open several pages of https://www.websocket.org/echo.html and connect to https://[host]/api/signalw/chat?connectionId=[any value]. Each page should broadcast messages to every other page and this is a simple chat.

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].