Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR how to preserve message order from server to client

I've got a problem that when I send messages from Server to client they don't arrive at the client in their original order. I've got a test function here:

public async Task Hello(string group)
    {
        await Groups.Add(Context.ConnectionId, group);
        await Clients.Group("grp1").Hello("grp1");
        await Clients.Group("grp2").Hello("grp2");
        await Clients.All.Hello("all");
    }

And on client:

var chanceHub = $.connection.chanceHub;
chanceHub.client.Hello = function (message) {
    alert(message);
}
$.connection.hub.start().done(function () {
    chanceHub.server.hello("grp1");
});

I expect to get 2 alerts in this order: "grp1" then "all" But I always get the message "all" first. Is there any way to solve this issue?

like image 760
CodeDemen Avatar asked Dec 21 '15 02:12

CodeDemen


People also ask

How do I send messages to a specific client in SignalR?

Each client connecting to a SignalR hub has a unique connection id. We can retrieve this using the Context.ConnectionId property of the hub context. Using this, we can send messages just to that particular client: By default, SignalR uses the ClaimTypes.NameIdentifier from the ClaimsPrincipal associated with the connection as the user identifier.

How many messages does Azure SignalR service send?

One client sends a 4-KB message to let the server broadcast to all clients. The billed message count is eight: one message from the service to the application server and three messages from the service to the clients. Each message is counted as two 2-KB messages. There are server connections and client connections with Azure SignalR Service.

Is there a SignalR documentation for the latest version of SignalR?

This documentation isn't for the latest version of SignalR. Take a look at ASP.NET Core SignalR. This document provides an introduction to programming the server side of the ASP.NET SignalR Hubs API for SignalR version 2, with code samples demonstrating common options.

What is a query string in SignalR?

The query string that you get in this property is the one that was used with the HTTP request that established the SignalR connection. You can add query string parameters in the client by configuring the connection, which is a convenient way to pass data about the client from the client to the server.


Video Answer


1 Answers

It's an unresolved issue #3310 for this problem. The issue also describes a workaround Issue #3310

like image 180
Espen Burud Avatar answered Oct 05 '22 06:10

Espen Burud