static void Main(string[] args)
        {
            Client client = null;

            try
            {
                ServerConfiguration cfg = new ServerConfiguration();
                //cfg.Host = "yourserver.com";
                //cfg.TlsConfiguration.Enabled = true;

                Dictionary <ushort, ProtocolConfiguration> protocolConfigurations =
                    new Dictionary <ushort, ProtocolConfiguration>();

                protocolConfigurations.Add(KeepAliveProtocol.PROTOCOL_IDENTIFIER,
                                           new ProtocolConfiguration(KeepAliveProtocol.PROTOCOL_IDENTIFIER, typeof(KeepAliveProtocol)));

                protocolConfigurations.Add(WinAuthProtocol.PROTOCOL_IDENTIFIER,
                                           new ProtocolConfiguration(WinAuthProtocol.PROTOCOL_IDENTIFIER, typeof(WinAuthProtocolClient)));

                protocolConfigurations.Add(HelloProtocol.PROTOCOL_IDENTIFIER,
                                           new ProtocolConfiguration(HelloProtocol.PROTOCOL_IDENTIFIER, typeof(HelloProtocolClient)));

                client = new Client(cfg, protocolConfigurations);
                client.Connect();

                ushort[] protocolIds = client.GetServerSupportedProtocolIds();
                foreach (int protocolId in protocolIds)
                {
                    Console.WriteLine("Server Supports Protocol ID: " + protocolId);
                }

                string userName           = "******";
                WinAuthProtocolClient wap = client.Initialize(WinAuthProtocol.PROTOCOL_IDENTIFIER) as WinAuthProtocolClient;
                if (!wap.Authenticate(userName, "T3stus3r", null))
                {
                    throw new Exception("Access denied.");
                }

                client.Initialize(KeepAliveProtocol.PROTOCOL_IDENTIFIER);

                HelloProtocolClient hpc = (HelloProtocolClient)client.Initialize(HelloProtocol.PROTOCOL_IDENTIFIER);
                string serverResponse   = hpc.Hello(userName);
                Console.WriteLine(serverResponse);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadKey();
                if (client != null)
                {
                    client.Close();
                }
            }
        }
示例#2
0
        private void Connect()
        {
            ServerConfiguration cfg = new ServerConfiguration();

            cfg.Host = txtHost.Text;
            //cfg.TlsConfiguration.Enabled = true;

            Dictionary <ushort, ProtocolConfiguration> protocolConfigurations =
                new Dictionary <ushort, ProtocolConfiguration>();

            protocolConfigurations.Add(KeepAliveProtocol.PROTOCOL_IDENTIFIER,
                                       new ProtocolConfiguration(KeepAliveProtocol.PROTOCOL_IDENTIFIER, typeof(KeepAliveProtocol)));

            protocolConfigurations.Add(WinAuthProtocol.PROTOCOL_IDENTIFIER,
                                       new ProtocolConfiguration(WinAuthProtocol.PROTOCOL_IDENTIFIER, typeof(WinAuthProtocolClient)));

            protocolConfigurations.Add(HelloProtocol.PROTOCOL_IDENTIFIER,
                                       new ProtocolConfiguration(HelloProtocol.PROTOCOL_IDENTIFIER, typeof(HelloProtocolClient)));

            client = new Client(cfg, protocolConfigurations);
            client.Logger.OnLogMessage += logger_OnLogMessage;
            client.OnConnectionLost    += client_OnConnectionLost;
            client.Connect();

            try
            {
                WinAuthProtocolClient wap = (WinAuthProtocolClient)client.Initialize(WinAuthProtocol.PROTOCOL_IDENTIFIER);
                if (!wap.Authenticate(txtUserName.Text, txtPassword.Password))
                {
                    throw new Exception("Access denied.");
                }

                client.Initialize(KeepAliveProtocol.PROTOCOL_IDENTIFIER);

                HelloProtocolClient hpc = (HelloProtocolClient)client.Initialize(HelloProtocol.PROTOCOL_IDENTIFIER);
                hpc.OnHelloComplete += hpc_OnHelloComplete;
                hpc.Hello(txtUserName.Text);
            }
            catch (Exception)
            {
                client.Close();
                throw;
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            Client client = null;

            try
            {
#if USE_APP_CONFIG
                client = new Client();
#else
                ServerConfiguration cfg = new ServerConfiguration();
                cfg.Host = "localhost";
                cfg.TlsConfiguration.Enabled = false;

                Dictionary <ushort, ProtocolConfiguration> protocolConfigurations =
                    new Dictionary <ushort, ProtocolConfiguration>();

                protocolConfigurations.Add(KeepAliveProtocol.PROTOCOL_IDENTIFIER,
                                           new ProtocolConfiguration(KeepAliveProtocol.PROTOCOL_IDENTIFIER, typeof(KeepAliveProtocol)));

                protocolConfigurations.Add(WinAuthProtocol.PROTOCOL_IDENTIFIER,
                                           new ProtocolConfiguration(WinAuthProtocol.PROTOCOL_IDENTIFIER, typeof(WinAuthProtocolClient)));

                protocolConfigurations.Add(HelloProtocol.PROTOCOL_IDENTIFIER,
                                           new ProtocolConfiguration(HelloProtocol.PROTOCOL_IDENTIFIER, typeof(HelloProtocolClient)));


                client = new Client(cfg, protocolConfigurations);
                //client.Logger.LogPackets = true;
                client.Logger.LogToDebuggerOutputView = true;
                client.Logger.LogDebug = true;
#endif

                client.Connect();

                ushort[] serverSupportedProtocolIds = client.GetServerSupportedProtocolIds();
                Console.WriteLine(string.Format(
                                      "Server Supported Protocol IDs: {0}",
                                      string.Join(", ", serverSupportedProtocolIds)));

                string userName           = "******";
                WinAuthProtocolClient wap = client.Initialize(WinAuthProtocol.PROTOCOL_IDENTIFIER) as WinAuthProtocolClient;
                wap.Authenticate(userName, "T3stus3r", null);
                if (!wap.IsAuthenticated)
                {
                    throw new Exception("Access denied.");
                }

                client.Initialize(KeepAliveProtocol.PROTOCOL_IDENTIFIER);

                HelloProtocolClient hpc = (HelloProtocolClient)client.Initialize(HelloProtocol.PROTOCOL_IDENTIFIER);
                string serverReponse    = hpc.Hello(userName);
                Console.WriteLine(serverReponse);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadKey();
                if (client != null)
                {
                    client.Close();
                }
            }
        }