-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWebSocketServer.cs
More file actions
49 lines (48 loc) · 1.76 KB
/
WebSocketServer.cs
File metadata and controls
49 lines (48 loc) · 1.76 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
using System.Net;
using System.Net.WebSockets;
using UiPath.Ipc.WebSockets;
namespace UiPath.Ipc.Tests;
class WebSocketServer
{
//private static readonly Timer _timer = new Timer(_ =>
//{
// Console.WriteLine("GC.Collect");
// GC.Collect();
// GC.WaitForPendingFinalizers();
// GC.Collect();
//}, null, 0, 3000);
static async Task _Main()
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
//GuiLikeSyncContext.Install();
Console.WriteLine(SynchronizationContext.Current);
var serviceProvider = ConfigureServices();
// build and run service host
//var data = File.ReadAllBytes(@"../../../../localhost.pfx");
var host = new ServiceHostBuilder(serviceProvider)
.UseWebSockets(new(new HttpSysWebSocketsListener("http://localhost:1212/wsDemo/").Accept)
{
RequestTimeout = TimeSpan.FromSeconds(2),
//Certificate = new X509Certificate(data, "1"),
})
.AddEndpoint<IComputingService, IComputingCallback>()
.AddEndpoint<ISystemService>()
.ValidateAndBuild();
await await Task.WhenAny(host.RunAsync(), Task.Run(() =>
{
Console.WriteLine(typeof(int).Assembly);
Console.ReadLine();
host.Dispose();
}));
Console.WriteLine("Server stopped.");
return;
}
private static IServiceProvider ConfigureServices() =>
new ServiceCollection()
.AddIpcWithLogging()
.AddSingleton<IComputingService, ComputingService>()
.AddSingleton<ISystemService, SystemService>()
.BuildServiceProvider();
}