1

Can you with SignalR send information the client who has send the request? Here I've quickly draw the current situation with paint:

The client send a SignalR request to the server with

meldingenHub.server.vote();

and the server send a message back to all the clients with

Clients.All.SendOke();

The situation I will have is that only the sender of that request, receive the message I send form the server. All the other clients don't receive that message. Is there something I can use like this:

Clients.Sender.SendOke();
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144

2 Answers2

2

When the Server method is invoked, there is a Context object populated with the details of who called the method. There is a property in here called ConnectionId which has the identifier of the caller.

So to invoke a method only on the sender's client, simply call:

await Clients.Client(Context.ConnectionId).SendAsync("ClientMetodName");

hugeandy
  • 203
  • 2
  • 7
1

What you need to do is send the connection id of the sender to the hub and then use Clients.Client(connId).broadcastMessage(....) see THIS other answer for an example.

Community
  • 1
  • 1