$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val(), $.connection.hub.id);
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
在服务器端发送客户端的id并响应该id
public void Send ( string name , string message , string connID )
{
Clients.Client(connID).broadcastMessage(name , message);
}
5 回答
查看最新文档:
持久连接 - https://github.com/SignalR/SignalR/wiki/PersistentConnection
枢纽 - http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server
在服务器端发送客户端的id并响应该id
每次向中心服务器发送请求时,您的请求都会有不同的连接ID,因此,我添加了一个静态哈希表,其中包含一个用户名 - 不会连续更改,并且每次都会返回信号r的连接ID您连接后,将更新连接ID
并在服务器代码中:
如果特定用户实际上是自己的来电者,您可以使用:
当您想要向特定ID发送消息时