asp.net クラシック Web サイトがあります。SignalR の基本機能が動作するようになりました (1 つのクライアントが残りのクライアントにメッセージを送信する場合)。しかし、今は特定の接続 ID にのみメッセージを送信したいと考えています。
私のハブ:
** [HubName("chatHub")]
public class ChatHub : Hub
{
public static List<string> messages = new List<string>();
public void GetServiceState()
{
Clients.updateMessages(messages);
}
public void UpdateServiceState()
{
messages.Add(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
Clients.updateMessages(messages);
}
}**
ASP コード:
<script type="text/javascript">
$(function () {
// creates a proxy to the health check hub
var healthCheckHub = $.connection.chatHub;
console.log($.connection.hub)
// handles the callback sent from the server
healthCheckHub.updateMessages = function (data) {
$("li").remove();
$.each(data, function () {
$('#messages').append('<li>' + this + '</li>');
console.log($.connection);
});
};
$("#trigger").click(function () {
healthCheckHub.updateServiceState();
});
// Start the connection and request current state
$.connection.hub.start(function () {
healthCheckHub.getServiceState();
});
});
Clients.updateMessages(メッセージ); それらすべてにメッセージを送信します。どうすればこれを解決できますか?
PS: すでに見ました: Signalr/PersistentConnection を使用して、接続されたクライアントにサーバー メッセージを送信します。
およびhttp://riba-escapades.blogspot.dk/2012/05/signalr-send-messages-to-single-client.html
それはうまくいきませんでした。