static async Task SslTest() { var x509Cert = GetXeenyTestCertificate(out string certName); var tcpAddress = $"tcp://localhost:9999/tcpTest"; var host = new ServiceHostBuilder <Service>(InstanceMode.PerConnection) .AddTcpServer(tcpAddress, options => { options.SecuritySettings = SecuritySettings.CreateForServer(x509Cert); options.FramingProtocol = FramingProtocol.ConcurrentFragments; }) .WithConsoleLogger(LogLevel.None) .CreateHost(); await host.Open(); var client = await new ConnectionBuilder <IService>() .WithTcpTransport(tcpAddress, options => { options.SecuritySettings = SecuritySettings.CreateForClient(certName); options.FramingProtocol = FramingProtocol.ConcurrentFragments; }) .WithConsoleLogger(LogLevel.None) .CreateConnection(); var msg = await client.Echo("test"); Console.WriteLine(msg); await host.Close(); ((IConnection)client).Close(); Console.WriteLine("Test Done!"); }
static async Task Profile(int count, SocketType socketType, bool useSsl, int serverSendBufferSize, int serverReciveBufferSize, int clientSendBufferSize, int clientReceiveBufferSize, FramingProtocol framingProtocol) { X509Certificate2 x509Cert = null; string certName = null; if (useSsl) { x509Cert = GetXeenyTestCertificate(out certName); } var httpAddress = $"http://localhost/test"; var tcpAddress = "tcp://localhost:9988"; var hostBuilder = new ServiceHostBuilder <Service>(InstanceMode.PerCall) .WithCallback <ICallback>() .WithMessagePackSerializer() //it is the default .WithConsoleLogger(); //default is empty ConnectionBuilder <IService> clientBuilder = null; if (socketType == SocketType.WebSocket) { hostBuilder.AddWebSocketServer(httpAddress, options => { options.ReceiveBufferSize = serverReciveBufferSize; options.SendBufferSize = serverReciveBufferSize; if (useSsl) { throw new NotImplementedException(); } }); clientBuilder = new ConnectionBuilder <IService>() .WithWebSocketTransport(httpAddress, options => { options.SendBufferSize = clientSendBufferSize; options.ReceiveBufferSize = serverReciveBufferSize; if (useSsl) { throw new NotImplementedException(); } }); } else if (socketType == SocketType.TCP) { hostBuilder.AddTcpServer(tcpAddress, options => { options.ReceiveBufferSize = serverReciveBufferSize; options.SendBufferSize = serverSendBufferSize; options.FramingProtocol = framingProtocol; if (useSsl) { options.SecuritySettings = SecuritySettings.CreateForServer(x509Cert); } }); clientBuilder = new ConnectionBuilder <IService>() .WithTcpTransport(tcpAddress, options => { options.SendBufferSize = clientSendBufferSize; options.ReceiveBufferSize = clientReceiveBufferSize; options.FramingProtocol = framingProtocol; if (useSsl) { options.SecuritySettings = SecuritySettings.CreateForClient(certName); } }); } var host = hostBuilder.CreateHost(); await host.Open(); Console.WriteLine("Host is open"); var client = await clientBuilder.CreateConnection(); //1 KB, the actual message on the wire will be more than 1 KB (depends on method type, name, and parameters) var msg = new string('*', 1000); for (int j = 0; j < 100; j++) { await Task.Delay(1000); var sw = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { var resp = await client.Echo(msg); //Task.Run(async () => //{ // var resp = await client.Echo(msg); // Console.WriteLine(resp.Length); //}); } sw.Stop(); Console.WriteLine($">> {sw.ElapsedMilliseconds}"); } }