markus / MarkusLogview / SignalREngine / Startup.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (2.53 KB)
1 | 84578b97 | djkim | using System; |
---|---|---|---|
2 | using System.Threading; |
||
3 | using System.Threading.Tasks; |
||
4 | using Microsoft.AspNet.SignalR; |
||
5 | using Microsoft.Owin; |
||
6 | using Microsoft.Owin.Cors; |
||
7 | using Microsoft.Owin.Hosting; |
||
8 | using Owin; |
||
9 | using SignalREngine; |
||
10 | |||
11 | [assembly: OwinStartup(typeof(Startup))] |
||
12 | |||
13 | namespace SignalREngine |
||
14 | { |
||
15 | public class Startup |
||
16 | { |
||
17 | static CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); |
||
18 | private static IDisposable _runningInstance; |
||
19 | // Your startup logic |
||
20 | public static void StartServer() |
||
21 | { |
||
22 | var cancellationTokenSource = new CancellationTokenSource(); |
||
23 | Task.Factory.StartNew(RunSignalRServer, TaskCreationOptions.LongRunning |
||
24 | , cancellationTokenSource.Token); |
||
25 | } |
||
26 | |||
27 | private static void RunSignalRServer(object task) |
||
28 | { |
||
29 | string url = "http://*:8089"; |
||
30 | _runningInstance = WebApp.Start(url); |
||
31 | } |
||
32 | |||
33 | public static void StopServer() |
||
34 | { |
||
35 | _cancellationTokenSource.Cancel(); |
||
36 | _runningInstance.Dispose(); |
||
37 | } |
||
38 | |||
39 | // This code configures Web API. The Startup class is specified as a type |
||
40 | // parameter in the WebApp.Start method. |
||
41 | public void Configuration(IAppBuilder app) |
||
42 | { |
||
43 | |||
44 | app.UseCors(CorsOptions.AllowAll); |
||
45 | app.Map("/signalr", map => |
||
46 | { |
||
47 | map.UseCors(CorsOptions.AllowAll); |
||
48 | var hubConfiguration = new HubConfiguration |
||
49 | { |
||
50 | }; |
||
51 | |||
52 | hubConfiguration.EnableDetailedErrors = true; |
||
53 | map.RunSignalR(hubConfiguration); |
||
54 | }); |
||
55 | } |
||
56 | |||
57 | protected void Application_Start( object sender , EventArgs e) |
||
58 | { |
||
59 | // Make long polling connections wait a maximum of 110 seconds for a |
||
60 | // response. When that time expires, trigger a timeout command and |
||
61 | // make the client reconnect. |
||
62 | GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110); |
||
63 | |||
64 | // Wait a maximum of 30 seconds after a transport connection is lost |
||
65 | // before raising the Disconnected event to terminate the SignalR connection. |
||
66 | GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(20); |
||
67 | |||
68 | // For transports other than long polling, send a keepalive packet every |
||
69 | // 10 seconds. |
||
70 | // This value must be no more than 1/3 of the DisconnectTimeout value. |
||
71 | GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10); |
||
72 | } |
||
73 | |||
74 | } |
||
75 | } |