我正在尝试了解信号器是如何工作的,所以我试图通过浏览器,集线器和浏览器发送消息。
到目前为止,我有这三个类
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Monitoring</title>
</head>
<body>
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
var chat = $.connection.MyHub;
$.connection.hub.start();
chat.server.sendMessageToWeb("hi", "hello");
chat.client.getData = function (name,message){
window.alert(name);
}
</script>
</body>
</html>
C#Hub:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace test
{
public class MyHub : Hub
{
public void sendMessageToWeb(String senderName, String message)
{
Clients.All.getData(senderName, message);
}
}
}
Owin Startup:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
网页加载并且只是空白而且不显示任何内容。