3

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

Thomas
  • 33,544
  • 126
  • 357
  • 626
  • https://github.com/SignalR/SignalR/wiki/Self-host https://github.com/SignalR/Samples/tree/master/BasicChat.SelfHost https://github.com/SignalR/Samples – Mou May 13 '13 at 19:34

1 Answers1

2

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.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • there is no class called WebApplication in the code which i got. – Thomas May 13 '13 at 13:57
  • @Thomas yes there is; it is in the `Microsoft.Owin.Hosting` namespace, and `Microsoft.Owin.Hosting.dll`, presumably via the `Microsoft.Owin.Hosting` package – Marc Gravell May 13 '13 at 14:00
  • if i copy the above code in my console apps the does it run without any error? – Mou May 13 '13 at 19:15
  • suppose i have a hub in web apps and through that hub message is push to other pages in my site. so i need to know if i want to push data from web apps to my console apps then do i need to self host or not? if possible tell me what i need to do at console end as a result message can be send and receive from my hub in web apps. thanks – Mou May 13 '13 at 19:22
  • @Mou are you the same user? Or is this an unrelated question? – Marc Gravell May 13 '13 at 19:24