forked from MV10/WebSocketExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (31 loc) · 1.17 KB
/
Copy pathProgram.cs
File metadata and controls
35 lines (31 loc) · 1.17 KB
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
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace WebSocketExample
{
class Program
{
public const int CLOSE_SOCKET_TIMEOUT_MS = 2500;
// async Main requires C# 7.2 or newer in csproj properties
static async Task Main(string[] args)
{
try
{
WebSocketServer.Start("http://localhost:8080/");
Console.WriteLine("Press any key to exit...\n");
Console.ReadKey(true);
await WebSocketServer.StopAsync();
}
catch(OperationCanceledException)
{
// this is normal when tasks are canceled, ignore it
}
// VS2019 prompts to close the console window by default
}
public static void ReportException(Exception ex, [CallerMemberName]string location = "(Caller name not set)")
{
Console.WriteLine($"\n{location}:\n Exception {ex.GetType().Name}: {ex.Message}");
if (ex.InnerException != null) Console.WriteLine($" Inner Exception {ex.InnerException.GetType().Name}: {ex.InnerException.Message}");
}
}
}