Ejemplo n.º 1
0
 private async void Connect()
 {
     await Task.Run(() =>
     {
         _client.Connect(Properties.Settings.Default.Host, Properties.Settings.Default.Port);
     });
 }
Ejemplo n.º 2
0
        /// <summary>Does a Logon with SSL.</summary>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        /// <param name="server">The server.</param>
        /// <param name="port">The port.</param>
        public void LoginSSL(string user, string password, string server, int port = 993)
        {
            var sslClient = new SslClient();

            sslClient.Connect(server, port);
            sslClient.DoClientTLS(server);
            stream = sslClient.Stream;
            Login(user, password);
        }
Ejemplo n.º 3
0
        public static void CreateServerAndConnectedClient(out SocketServer server,
                                                          out SslClient client1, out SslClient client2)
        {
            var connected1 = new ManualResetEventSlim(false);
            var connected2 = new ManualResetEventSlim(false);

            var ex = ServerHelpers.CreateExecutor();
            var s  = ServerHelpers.CreateServer();

            SslClient lClient = null;
            SslClient sClient = null;

            var certBytesStream = Assembly.GetExecutingAssembly()
                                  .GetManifestResourceStream("Stacks.Tests.StacksTest.pfx");
            var certBytes = new BinaryReader(certBytesStream).ReadBytes((int)certBytesStream.Length);

            s.Connected.Subscribe(c =>
            {
                sClient = new SslClient(c, new X509Certificate2(certBytes));

                sClient.Connected.Subscribe(_ =>
                {
                    connected2.Set();
                });

                sClient.EstablishSsl();
            });

            s.Started.Subscribe(_ =>
            {
                lClient = new SslClient(new SocketClient(ex), "Stacks Test", true);

                lClient.Connected.Subscribe(__ =>
                {
                    connected1.Set();
                });

                lClient.Connect(new IPEndPoint(IPAddress.Loopback, s.BindEndPoint.Port));
            });

            s.Start();

            connected1.AssertWaitFor(300000);
            connected2.AssertWaitFor(300000);

            server  = s;
            client1 = lClient;
            client2 = sClient;
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            //Uid setzen:
            Console.Write("Set your Uid: ");
            _uid = Console.ReadLine();


            _client = new SslClient(NetworkUtilities.GetThisIPv4Adress(), true);

            _client.ConnectionLost    += OnConnectionLost;
            _client.ConnectionSucceed += OnConnectionSucceed;
            _client.PackageReceived   += OnPackageReceived;

            _client.Connect(NetworkUtilities.GetThisIPv4Adress(), 9999);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            SslClient client = new SslClient();

            // Bind the client events
            client.Connected       += OnConnected;
            client.Disconnected    += OnDisconnected;
            client.MessageReceived += OnMessageReceived;

            // Connect to the endpoint and the matching server certificate subject name
            client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80), "MyServerCertificateCN");

            while (true)
            {
                if (_bIsConnected)
                {
                    Console.Clear();
                    Console.WriteLine("Enter a message to the server:");

                    string input = Console.ReadLine();

                    if (input.ToLower() == "exit" || input.ToLower() == "quit")
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        client.Write(input);
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Waiting for connection. . .");
                }
            }
        }