コード例 #1
0
 public ChatSession(ChatServiceImpl service, string username, IMessageHandler handler)
 {
     this.Service  = service;
     this.Username = username;
     this.Handler  = handler;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: E1izabeth/Serializer
        static void DoServer()
        {
            Console.WriteLine("\nServer mode");
            Console.WriteLine("----------------------------");
            var svc = new ChatServiceImpl();

            var activeSessions = new LinkedList <IRpcChannel <IChatService> >();

            using (var listener = _host.Listen(_binaryTcpProtocol, new IPEndPoint(IPAddress.Any, 12345)))
            {
                listener.Start();

                do
                {
                    var ctx            = listener.AcceptChannelAsync();
                    var sessionSvcStub = new ChatServiceStub(svc);
                    var channel        = ctx.Result.Confirm(sessionSvcStub);

                    lock (activeSessions)
                    {
                        channel.OnClosed += () =>
                        {
                            lock (activeSessions)
                                activeSessions.Remove(channel);

                            sessionSvcStub.CleanupSession();
                        };

                        activeSessions.AddLast(channel);
                    }

                    channel.Start();
                } while (Console.ReadKey().Key != ConsoleKey.Q);

                //Action<IRpcChannelAcceptContext<IPEndPoint, IChatService>> acceptHandler = null;
                //acceptHandler = ctx =>
                //{
                //    var sessionSvcStub = new ChatServiceStub(svc);
                //    var channel = ctx.Confirm(sessionSvcStub);

                //    lock (activeSessions)
                //    {
                //        channel.OnClosed += () =>
                //        {
                //            lock (activeSessions)
                //                activeSessions.Remove(channel);

                //            sessionSvcStub.CleanupSession();
                //        };

                //        activeSessions.AddLast(channel);
                //    }

                //    channel.Start();

                //    listener.AcceptChannelAsync(acceptHandler);
                //};

                //listener.AcceptChannelAsync(acceptHandler);

                Console.ReadLine();
            }
        }
コード例 #3
0
 public ChatServiceStub(ChatServiceImpl svc)
 {
     _svc = svc;
 }