Regarding hosting SignalR in console apps

北城余情 提交于 2019-12-10 10:19:59

问题


i got a code which host SignalR in console apps. here is the code.

Install-Package Microsoft.Owin.Hosting -pre
Install-Package Microsoft.Owin.Host.HttpListener -pre
Install-Package Microsoft.AspNet.SignalR.Owin -pre

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

namespace SignalR.Hosting.Self.Samples
{
class Program
{
    static void Main(string[] args)
    {
        string url = "http://172.0.0.01:8080";

        using (WebApplication.Start<Startup>(url))
        {
            Console.WriteLine("Server running on {0}", url);
            Console.ReadLine();
        }
    }
}

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        // This will map out to http://localhost:8080/signalr by default
        // This means a difference in the client connection.

        app.MapHubs();
    }
}

public class MyHub : Hub
{
    public void Send(string message)
    {
        Clients.All.addMessage(message);
    }
}

}

i just do not understand this line using (WebApplication.Start<Startup>(url)) i just also do not understand the usage of Startup class

anyone can help me to understand the above code. thanks


回答1:


The Startup class shown here is where you configure SignalR; in this case it is using a basic approach that is just going to find all the hubs (the Hub subclasses in the calling assembly) and throw them into the mix by-name - but more subtle configurations are possible. The WebApplication.Start<Startup>(url) is invoking all that configuration code, along with the plumbing to get a listener, etc to do some actual work. Ultimately it is the Hub that has the interesting code here, i.e. where your code goes.



来源:https://stackoverflow.com/questions/16523691/regarding-hosting-signalr-in-console-apps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!