Beispiel #1
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();
                }
            }
        }