我的.net客户端代码是:
var hubConnection = new HubConnection("http://localhost/signalrServer");
IHubProxy myproxy = hubConnection.CreateHubProxy("ChatHub");
hubConnection.Start().Wait();
//hubConnection.ma
myproxy.Invoke("JoinGroup", "MapRoom");
while (true)
{
System.Threading.Thread.Sleep(1000);
myproxy.Invoke("callFromService", new Random().NextDouble().ToString());
}
我的信号中心服务器代码:
public class ChatHub : Hub
{
public void CallFromService(string message)
{
// Call the broadcastMessage method to update clients.
//Clients.All.broadcastMessage(name, message);
Clients.All.broadcastMessage(message);
}
}
我的网络客户端代码是
$(function () {
debugger;
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
//chat.logging = true;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (message) {
debugger;
angular.element(document.getElementById('mapdiv')).scope().$apply(function (scope) {
scope.mapMsg = message;
});
};
// Get the user name and store it to prepend to messages.
$.connection.hub.start().done(function () {
debugger;
//chat.server.joinGroup("MapRoom");
});
});
此代码只能在一个Web客户端上运行 如果我在新标签或新浏览器上打开同一页面,它会卡住。 当我关闭一个标签然后它的工作......
我希望服务器更新所有网络客户端。