0
votes

I have an existing service that notifies a large number of clients when an event occurs. It uses a long polling mechanism that I rolled myself. I'm exploring replacing that mechanism with a signalr hub, and have a prototype working. But it has a pretty significant inefficiency that feels like there should be a solution to, but I'm not finding it.

I understand the idea of groups in signalr, and groups are obviously intended to prevent this inefficiency, but there is a reason that I cannot use groups. I hope it suffices to say that I need to call the same client method, with the same parameter values, on many clients using each client's ConnectionId. I can explain why if necessary, but it's really beside the point.

Assume I have a list of 200 ConnectionId's and I need to call the same method on each of them passing the same object parameter. If I simply iterate through the ConnectionId's calling Clients.Client(ConnectionId).clientMethod(param), I presume that the param object would be serialized 200 times.

Is there a way to serialize the parameter(s) one time, then invoke the client method using the already-serialized parameters?

UPDATE

I've found a github issue that sounds related (maybe even this exact issue) at Allow to Send Json Strings without duplicate Serialization. It appears that the functionality was added to signalr, but the github issue doesn't say anything about how to do it, and I can't find anything regarding it in the signalr docs.

UPDATE 2

In the github issue referenced above, the new functionality was implemented for PersistentConnection only -- not hubs. With persistent connections, when sending a parameter of type ArraySegment, signalr assumes it to be pre-serialized and sends it as-is without serializing it.

For some reason, this was not implemented for hubs, although it would be useful for hubs for the same reason it was useful for persistent connections.

1

1 Answers

0
votes

Store all connectionId's in a Static List<string> atOnConnected` event and use the following,

Static List<string> allconnections = new List<string>();
    public override Task OnConnected()
        {
           allconnections.Add(Context.ConnectionId);
           return base.OnConnected();
         }

Public void YourServerMethod(params)
{
     Clients.Clients(allConnections).clientMethod(params)
}