Пример #1
0
        private void Working()
        {
            Receive <NewConnection>(msg =>
            {
                Context.Stop(_connectionActor);

                _endpoint = msg.EndPoint;
                var name  = $"tcp-connection-{_name}";
                var self  = Self;

                _connectionActor = Context.ActorOf(TcpConnectionActor.GetProps(name, _endpoint, self));

                Become(Working);
            });

            Receive <CloseConnection>(msg =>
            {
                Context.Stop(_connectionActor);
                Become(Ready);
            });

            Receive <TcpConnectionActor.TcpDataReceived>(msg =>
            {
                foreach (var sub in _subscribers)
                {
                    sub.Value.Tell(msg.Data);
                }
            });

            //Add subscription logic receive handlers
            SubscriptionHandlers();
        }
Пример #2
0
        private void Ready()
        {
            Receive <NewConnection>(msg =>
            {
                _endpoint = msg.EndPoint;
                var name  = $"tcp-connection-{_name}";
                var self  = Self;

                _connectionActor = Context.ActorOf(TcpConnectionActor.GetProps(name, _endpoint, self));

                Become(Working);
            });

            //Add subscription logic receive handlers
            SubscriptionHandlers();
        }