-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTcpServer.cs
More file actions
53 lines (47 loc) · 1.73 KB
/
TcpServer.cs
File metadata and controls
53 lines (47 loc) · 1.73 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
50
51
52
53
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
using System.Net;
using UiPath.Ipc.Tcp;
namespace UiPath.Ipc.Tests;
class TcpServer
{
static readonly IPEndPoint SystemEndPoint = new(IPAddress.Any, 3131);
//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)
.UseTcp(new TcpSettings(SystemEndPoint)
{
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.");
}
private static IServiceProvider ConfigureServices() =>
new ServiceCollection()
.AddIpcWithLogging()
.AddSingleton<IComputingService, ComputingService>()
.AddSingleton<ISystemService, SystemService>()
.BuildServiceProvider();
}