示例#1
1
文件: WorkerRole.cs 项目: yallie/zyan
        public override void Run()
        {
            Trace.WriteLine("Zyan.Examples.MiniChat.AzureWorkerRole entry point called", "Information");

            IPEndPoint endPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MiniChat"].IPEndpoint;
            TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(endPoint.Port, new NicknameAuthProvider(), true);

            ActiveNicknames = new List<string>();

            ZyanComponentHost host = new ZyanComponentHost("MiniChat", protocol);
            host.RegisterComponent<IMiniChat, Zyan.Examples.MiniChat.Server.MiniChat>(ActivationType.Singleton);

            host.ClientLoggedOn += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Trace.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged on.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Add(e.Identity.Name);
                });
            host.ClientLoggedOff += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Trace.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged off.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Remove(e.Identity.Name);
                });

            while (true)
            {
                Thread.Sleep(10000);
                Trace.WriteLine("Working", "Information");
            }
        }
示例#2
0
文件: Program.cs 项目: yallie/zyan
 public static void Main(string[] args)
 {
     var protocol = new TcpDuplexServerProtocolSetup(12345, new NullAuthenticationProvider(), true);
     using (var host = new ZyanComponentHost("Sample", protocol))
     {
         host.RegisterComponent<ISampleService, SampleService>();
         Console.WriteLine("Server started. Press Enter to exit.");
         Console.ReadLine();
     }
 }
示例#3
0
文件: Program.cs 项目: yallie/zyan
        static void Main(string[] args)
        {
            var protocol = new TcpDuplexServerProtocolSetup(8081,null,true);

            using (var host = new ZyanComponentHost("WhisperChat", protocol))
            {
                host.RegisterComponent<IWhisperChatService, WhisperChatService>(ActivationType.SingleCall);

                Console.WriteLine("Server running.");
                Console.ReadLine();
            }
        }
示例#4
0
        public void CreateDisposeAndRecreateComponentHostForTcpDuplexChannel()
        {
            var protocol = new TcpDuplexServerProtocolSetup(8086, new NullAuthenticationProvider(), true);

            using (var host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpDuplex", protocol))
            {
                host.RegisterComponent<ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }

            using (var host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpDuplex", protocol))
            {
                host.RegisterComponent<ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
            }
        }
示例#5
0
文件: Program.cs 项目: yallie/zyan
        static void Main(string[] args)
        {
            ActiveNicknames = new List<string>();

            TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(Properties.Settings.Default.TcpPort, new NicknameAuthProvider(), true);

            using (ZyanComponentHost host = new ZyanComponentHost("MiniChat", protocol))
            {
                host.PollingEventTracingEnabled = true;
                host.ClientHeartbeatReceived += new EventHandler<ClientHeartbeatEventArgs>(host_ClientHeartbeatReceived);

                host.RegisterComponent<IMiniChat, MiniChat>(ActivationType.Singleton);

                host.ClientLoggedOn += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Console.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged on.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Add(e.Identity.Name);
                });

                host.ClientLoggedOff += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Console.WriteLine(string.Format("{0}: User '{1}' with IP {2} logged off.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Remove(e.Identity.Name);
                });

                host.ClientSessionTerminated += new EventHandler<LoginEventArgs>((sender, e) =>
                {
                    Console.WriteLine(string.Format("{0}: User '{1}' with IP {2} was kicked due to inactivity.", e.Timestamp.ToString(), e.Identity.Name, e.ClientAddress));
                    ActiveNicknames.Remove(e.Identity.Name);
                });

                host.EnableDiscovery();
                Console.WriteLine("Chat server started. Press Enter to exit.");
                Console.ReadLine();
            }
        }
 private TcpDuplexServerHostEnvironment()
 {
     var protocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true);
     _host = new ZyanComponentHost("RecreateClientConnectionTestHost_TcpDuplex", protocol);
     _host.RegisterComponent<ISampleServer, SampleServer>("SampleServer", ActivationType.SingleCall);
 }
示例#7
0
        private EventServer()
        {
            _catalog = new ComponentCatalog();
            _catalog.RegisterComponent<IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent<IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent<ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<ITimerTriggeredEvent, TimerTriggeredEvent>(ActivationType.Singleton);

            // Setting compression threshold to 1 byte means that all messages will be compressed.
            // This setting should not be used in production code because smaller packets will grow in size.
            // By default, Zyan only compresses messages larger than 64 kilobytes.
            var tcpBinaryProtocol = new TcpBinaryServerProtocolSetup(8082);
            tcpBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.LZF));
            _tcpBinaryHost = new ZyanComponentHost("TcpBinaryEventTest", tcpBinaryProtocol, _catalog);

            var ipcBinaryProtocol = new IpcBinaryServerProtocolSetup("IpcTestServer");
            ipcBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.DeflateStream));
            _ipcBinaryHost = new ZyanComponentHost("IpcBinaryEventTest", ipcBinaryProtocol, _catalog);

            var tcpCustomProtocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true)
            {
             				CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.DeflateStream
            };
            _tcpCustomHost = new ZyanComponentHost("TcpCustomEventTest", tcpCustomProtocol, _catalog);

            var tcpDuplexProtocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.DeflateStream
            };
            tcpDuplexProtocol.AddChannelSetting("bindTo", "127.0.0.1");

            _tcpDuplexHost = new ZyanComponentHost("TcpDuplexEventTest", tcpDuplexProtocol, _catalog);

            var httpCustomProtocol = new HttpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.LZF
            };
            _httpCustomHost = new ZyanComponentHost("HttpCustomEventTest", httpCustomProtocol, _catalog);

            var nullChannelProtocol = new NullServerProtocolSetup(1234);
            _nullChannelHost = new ZyanComponentHost("NullEventTest", nullChannelProtocol, _catalog);

            // use legacy blocking events mode because we check the handlers synchronously
            ZyanComponentHost.LegacyBlockingEvents = true;
        }