-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Program.cs
58 lines (49 loc) · 1.68 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using SignalR.Samples.Raw;
namespace SignalR.Hosting.Self.Samples
{
class Program
{
static void Main(string[] args)
{
Debug.Listeners.Add(new ConsoleTraceListener());
Debug.AutoFlush = true;
string url = "http://localhost:8081/";
var server = new Server(url);
server.Configuration.DisconnectTimeout = TimeSpan.Zero;
// Map connections
server.MapConnection<MyConnection>("/echo")
.MapConnection<Raw>("/raw")
.MapHubs();
server.Start();
Console.WriteLine("Server running on {0}", url);
while (true)
{
ConsoleKeyInfo ki = Console.ReadKey(true);
if (ki.Key == ConsoleKey.X)
{
break;
}
}
}
public class MyConnection : PersistentConnection
{
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
Console.WriteLine("{0} connected", connectionId);
return base.OnConnectedAsync(request, connectionId);
}
protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
return Connection.Broadcast(data);
}
protected override Task OnDisconnectAsync(string connectionId)
{
Console.WriteLine("{0} left", connectionId);
return base.OnDisconnectAsync(connectionId);
}
}
}
}