Signalr 如何在winforms中进行信号员聊天

Signalr 如何在winforms中进行信号员聊天,signalr,Signalr,我是新做客户端服务器应用程序的,我有一个问题。我想用C#和SignalR创建一个简单的聊天,但我需要在winforms.Net框架(客户端)和控制台项目中的服务器中完成。我搜索了很多信息,但所有人都只在asp.net项目中搜索。我试图修改代码,但遇到了很多问题。我对这个话题有点迷糊了,有人能帮我一下吗?非常感谢您的反馈。您可以在Startup和Program(c#)课程中设置SignalR,如下所示: 使用系统; 使用Microsoft.AspNet.signal; 使用Microsoft.Ow

我是新做客户端服务器应用程序的,我有一个问题。我想用C#和SignalR创建一个简单的聊天,但我需要在winforms.Net框架(客户端)和控制台项目中的服务器中完成。我搜索了很多信息,但所有人都只在asp.net项目中搜索。我试图修改代码,但遇到了很多问题。我对这个话题有点迷糊了,有人能帮我一下吗?非常感谢您的反馈。

您可以在Startup和Program(c#)课程中设置SignalR,如下所示:

使用系统;
使用Microsoft.AspNet.signal;
使用Microsoft.Owin.Cors;
使用Microsoft.Owin.Hosting;
使用Owin;
名称空间信号服务器
{
班级计划
{
静态void Main(字符串[]参数)
{
变量url=”http://localhost:8080/";
使用(WebApp.Start(url))
{
WriteLine($“在{url}上运行的服务器”);
Console.ReadLine();
}
}
}
公营创业
{
公共无效配置(IAppBuilder应用程序)
{
应用程序UseCors(CorsOptions.AllowAll);
app.MapSignalR(“/signalchat”,新的HubConfiguration());
}
}
}
您可以在此处找到详细信息:

有关控制台应用程序,请参阅此GitHub存储库:

using System;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Cors;
using Microsoft.Owin.Hosting;
using Owin;


namespace SignalServer
{
    class Program
    {
        static void Main(string[] args)
        {
            var url = "http://localhost:8080/";
            using (WebApp.Start<Startup>(url))
            {
                Console.WriteLine($"Server running at {url}");
                Console.ReadLine();
            }
        }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR("/signalchat", new HubConfiguration());
        }
    }
}