Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("TLS example");


            var serializer = new StringMessageSerializer();

            var serverTlsWrapper = new ServerTlsWrapper(new X509Certificate2("server.pfx"), false, CertificateValidationCallback);

            ICommunication <StringMessage> serverCommunication =
                new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Any, 2000),
                                                     serializer,
                                                     ChannelSettings.GetDefault(),
                                                     TcpConnectionSettingsBuilder.GetDefaultSettings(),
                                                     serverTlsWrapper);

            var server = Scenarios.RequestResponse.SetupServer(serverCommunication)
                         .UsingNewClientHandler((sender, a) => { Console.WriteLine("channel opened"); })
                         .UsingRequestHandler((sender, a) => { a.Response = new StringMessage(a.Request.Message.Replace("request", "response")); })
                         .UsingChannelClosedHandler((sender, a) => { Console.WriteLine("channel closed"); })
                         .Go();

            var clientTlsWrapper = new ClientTlsWrapper("SharpChannels Example Server Certificate",
                                                        new X509Certificate[] { new X509Certificate2("client.pfx") },
                                                        false,
                                                        CertificateValidationCallback);

            ICommunication <StringMessage> clientCommunication =
                new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                     serializer,
                                                     ChannelSettings.GetDefault(),
                                                     TcpConnectionSettingsBuilder.GetDefaultSettings(),
                                                     clientTlsWrapper);

            var r = Scenarios.RequestResponse.Requester(clientCommunication);

            using (r.Channel)
            {
                r.Channel.Open();

                var requester = new Requester(r.Channel);

                var requestMessage = new StringMessage($"request using tls");
                Console.WriteLine(requestMessage);

                var responseMessage = requester.Request(requestMessage);
                Console.WriteLine(responseMessage);

                r.Channel.Close();
            }

            server.Stop();

            Console.ReadKey();
        }
Esempio n. 2
0
        private ICommunication <StringMessage> GetTcpSubscriberCommunication()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            return(new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                        new StringMessageSerializer(),
                                                        ChannelSettings.GetDefault(),
                                                        connectionSettings,
                                                        null));
        }
Esempio n. 3
0
        private IPublisher <StringMessage> StartTcpPublisher()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var communication = new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Any, 2000),
                                                                     new StringMessageSerializer(),
                                                                     ChannelSettings.GetDefault(),
                                                                     connectionSettings,
                                                                     null);

            return(Scenarios.PubSub.Publisher(communication));
        }
        private IRequester GetTcpRequester()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var clientCommunication = new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Loopback, 2000),
                                                                           new StringMessageSerializer(),
                                                                           ChannelSettings.GetDefault(),
                                                                           connectionSettings,
                                                                           null);

            return(Scenarios.RequestResponse.Requester(clientCommunication));
        }
        private NewChannelRequestAcceptor StartTcpServer()
        {
            var connectionSettings = new TcpConnectionSettingsBuilder()
                                     .UsingSendTimeout(TimeSpan.FromHours(1))
                                     .UsingReceiveTimeout(TimeSpan.FromHours(1))
                                     .Build();

            var communication = new TcpCommunication <StringMessage>(new TcpEndpointData(IPAddress.Any, 2000),
                                                                     new StringMessageSerializer(),
                                                                     ChannelSettings.GetDefault(),
                                                                     connectionSettings,
                                                                     null);

            return(StartServer(communication));
        }
Esempio n. 6
0
 public TcpCommunication(TcpEndpointData endpointData, IMessageSerializer serializer)
     : this(endpointData, serializer, ChannelSettings.GetDefault(), TcpConnectionSettingsBuilder.GetDefaultSettings(), null)
 {
 }