有没有关于如何将 SignalR 与控制台应用程序一起使用的示例?我已经阅读了 wiki,但我无法运行我的应用程序,我会告诉你我做了什么
服务器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNet.SignalR;
using System.Threading.Tasks;
using System;
using Owin;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.Owin.Hosting;
namespace SignalRChat.Server
{
class Program
{
static void Main(string[] args)
{
string url = "http://localhost:8083";
using (WebApplication.Start<Startup>(url)) {
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapHubs();
}
}
}
集线器类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNet.SignalR.Hubs;
namespace SignalRChat.Server
{
public class ChatHub : Hub
{
public void Send(string message)
{
Clients.All.addMessage(message);
}
}
}
客户:
<html>
<head>
<title>SignalR client</title>
<script type="text/javascript" src="Scripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.signalR-0.5.1.min.js"></script>
<script type="text/javascript" src="http://localhost:8083/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
// Proxy created on the fly
var myHub = $.connection.chatHub;
// Start the connection
$.connection.hub.url = 'http://localhost:8083/signalr';
$.connection.hub.start().done(function () {
alert("Now connected!");
}).fail(function () {
alert("Could not Connect!");
});
});
</script>
</head>
<body>
<ul id="messages"></ul>
</body>
</html>
我总是收到无法连接警报我的代码中是否有任何逻辑错误?