Reputation: 9015
I use class Echo
derived from PersistentConnection
, and I want to send a message to certain connection:
var client = GlobalHost.ConnectionManager.GetConnectionContext<Echo>();
client.Connection.Broadcast(msg);
But I want to send it to specific connection ID. Do I have to create a group for every connection or start using Hubs, or there is a simpler way to select connection by ID, something like:
GetConnectionById(id).Send(msg);
?
Upvotes: 3
Views: 2075
Reputation: 4303
Message can be sent to a specific connection ID, but the syntax is not same as what you specified in the question. Following snippet shows the syntax:
return Connection.Send(connectionId, Message);
Source of my answer: SignalR wiki on Github
I think, you are aware that SignalR 1 Alpha is released. It is possible to send message to a specific client by its ID if you use this version. Following snippet shows it:
var connection = GlobalHost.ConnectionManager.GetConnectionContext<Echo>().Connection;
connection.Send(((Connection)connection).Identity, "Message to be sent");
Here, ((Connection)connection).Identity
gives connection ID of the requesting client.
Upvotes: 2