我正在玩signalR 的新1.0alpha2 版本。我想在 ASP.NET 应用程序之外实现 SignalR 服务器。这样两个控制台应用程序就可以相互通信。
使用旧的 0.5.3 版本,我能够“Install-Package SignalR.Hosting.Self”到:
var server = new Server("http://127.0.0.1:8088/");
但是在新的 1.0alpha2 版本中,我无法安装这个 NuGet 包......
谁能给我一个链接或两个基于1.0alpha2版本的控制台应用程序的工作迷你示例。(我只能找到不工作的旧 0.5.3 示例......)。
行。所以我听从了你的指示。现在:
我的客户端控制台:
class Programm
{
static void Main(string[] args)
{
var connection = new HubConnection("http://localhost/");
IHubProxy myHub = connection.CreateHubProxy("MyHub");
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
Console.WriteLine("No Connection: " + task.Exception.GetBaseException());
else
Console.WriteLine("Connected!");
});
myHub.Invoke("Send");
Console.ReadLine(); // wait...
}
}
这是我的服务器控制台:
class Program : Hub
{
static void Main(string[] args)
{
Console.ReadKey();
}
public void Send(string message)
{
Debug.WriteLine("Server Method [send] was called");
Console.WriteLine("Server Method [send] was called");
}
}
但我认为这是胡说八道......