Skip to content
Advertisement

How to use SignalR to send data to a specific user?

I have a client which receives messages over SignalR. It is working great but it is more like a broadcast. I would like to be able to send messages to a specific client. On the client-side I have a userId and I set up my connection like this:

JavaScript

On the server-side (Azure Function written in JavaScript) I have a message and a userId. The question for me is how does the server know which SignalR connection is going to this specific user? Can I somehow tell SignalR who I am?

Advertisement

Answer

Using the Azure SignalR Service and the client-side code from the question I was able to get it to work. I used the following Azure Function to negotiate the connection:

JavaScript

JavaScript

As well as another function to send a message to a specific user:

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement