Can I have multiple “categories” on one connection?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Can I have multiple “categories” on one connection?



I'll be designing a SPA with Angular 6 and .netcore 2 as a backend API. I'm going to need a socket implementation for live data streaming and charting purposes.



I have a page that requires 3 different data types "live streamed" and my question is - can I do this with one websocket connection? As far as I know, I think that there is a way to create some kind of a queue in the connection or something like a substream, so I can have something like the following:


socket = new WebSocket(url);
socket.on('dataOne', () => // proccess here
socket.on('dataTwo', () => // proccess here
socket.on('dataThree', () => // proccess here



I'm wondering if this is possible and if it is, can you advise me on a lib that I can use for the Client and the API?



I've researched libs like SignalR for C# and Substream, but I'm not completely sure. All kinds of advises and explanations are appreciated!




2 Answers
2



There are existing SignalR clients for both JavaScript and C#. You should use those. Other than that, I'm not honestly sure what you're talking about. You don't need separate hubs, if that's what you mean. Ultimately, SignalR is really pretty simplistic: you simply send a message and the client binds to that message type and does something when it receives it. The reverse process is largely the same: the client simply "invokes" some method defined on your hub, which then does something.



As such, you can bind to pretty much anything client-side, and the server just needs to send that particular message to cause something to happen. For example:


let connection = new signalR.HubConnectionBuilder()
.withUrl("/myhub")
.build();
connection.on("dataOne", data => ... );
connection.on("dataTwo", data => ... );
connection.on("dataThree", data => ... );
connection.start().catch(err => console.error(err.toString()));



Then, server-side:


await _hub.Clients.All.SendAsync("dataOne", data);



you should keep the connection to one only and use multiple proxies for your categories.
something like this


var contosoChatHubProxy = connection.createHubProxy('ContosoChatHub');
contosoChatHubProxy.on('addContosoChatMessageToPage', function(userName, message)
console.log(userName + ' ' + message);
);

var categoryOneHubProxy = connection.createHubProxy('categoryOne');
var categoryTwoHubProxy = connection.createHubProxy('categoryTwo');



for detail refer






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard