示例#1
0
        static void Main()
        {
            var serverPublicKey = new X509Certificate2(@"C:\Users\node\Desktop\scs\SSLSamples\CertificateFiles\Server\publicKey.cer");

            Console.WriteLine("Press enter to connect to the server...");
            Console.ReadLine(); //Wait user to press enter

            //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
            // using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10085)))
            using (var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10085)
                                                                    , serverPublicKey
                                                                    , "127.0.0.1"))
            {
                //Create a SynchronizedMessenger that uses the client as internal messenger.
                using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client))
                {
                    synchronizedMessenger.Start(); //Start synchronized messenger messenger
                    client.Connect();              //Connect to the server

                    Console.Write("Write some message to be sent to server: ");
                    var messageText = Console.ReadLine(); //Get a message from user

                    //Send a message to the server
                    synchronizedMessenger.SendMessage(new ScsTextMessage(messageText));

                    //Receive a message from the server
                    var receivedMessage = synchronizedMessenger.ReceiveMessage <ScsTextMessage>();

                    Console.WriteLine("Response to message: " + (receivedMessage.Text));

                    Console.WriteLine("Press enter to disconnect from server...");
                    Console.ReadLine(); //Wait user to press enter
                }
            }
        }
        public static void Run()
        {
            Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages.");
            Console.ReadLine();

            //using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033)))
            using (var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10033), Consts.ServerPublicKey, "127.0.0.1"))
            {
                client.WireProtocol = new MyWireProtocol();
                using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client))
                {
                    synchronizedMessenger.Start();
                    client.Connect();

                    for (var i = 0; i < Consts.MessageCount; i++)
                    {
                        synchronizedMessenger.SendMessage(new ScsTextMessage("Hello from client!"));
                        var reply = synchronizedMessenger.ReceiveMessage <ScsTextMessage>();
                    }
                }

                Console.WriteLine("Press enter to disconnect from server");
                Console.ReadLine();
            }
        }
示例#3
0
文件: Program.cs 项目: SariSultan/scs
        static void Main()
        {
            var serverPublicKey = new X509Certificate2(@"C:\Users\node\Desktop\scs\SSLSamples\CertificateFiles\Server\publicKey.cer");
            //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
            //var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10085));
            var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10085)
                                                             , serverPublicKey
                                                             , "127.0.0.1"
                                                             );

            //Register to MessageReceived event to receive messages from server.
            client.MessageReceived += Client_MessageReceived;

            Console.WriteLine("Press enter to connect to the server...");
            Console.ReadLine(); //Wait user to press enter

            client.Connect();   //Connect to the server

            Console.Write("Write some message to be sent to server: ");
            var messageText = Console.ReadLine(); //Get a message from user

            //Send message to the server
            client.SendMessage(new ScsTextMessage(messageText));

            Console.WriteLine("Press enter to disconnect from server...");
            Console.ReadLine();  //Wait user to press enter

            client.Disconnect(); //Close connection to server
        }
        public static void Run()
        {
            Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages.");
            Console.ReadLine();

            // using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033)))
            using (var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10033), Consts.ServerPublicKey, "127.0.0.1"))
            {
                client.Connect();

                for (var i = 0; i < Consts.MessageCount; i++)
                {
                    client.SendMessage(new ScsTextMessage("Hello from client!"));
                }

                Console.WriteLine("Press enter to disconnect from server");
                Console.ReadLine();
            }
        }
示例#5
0
文件: Program.cs 项目: SariSultan/scs
        static void Main()
        {
            var serverPublicKey =
                new X509Certificate2(@"C:\Users\node\Desktop\scs\SSLSamples\CertificateFiles\Server\publicKey.cer");

            Console.WriteLine("Press enter to connect to server and say Hello world!");
            Console.ReadLine();

            //using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033)))
            using (var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10033)
                                                                    , serverPublicKey
                                                                    , "127.0.0.1"))
            {
                client.WireProtocol = new MyWireProtocol(); //Set custom wire protocol!

                client.Connect();
                client.SendMessage(new ScsTextMessage("Hello world!"));

                Console.WriteLine("Press enter to disconnect from server");
                Console.ReadLine();
            }
        }