Пример #1
0
        private static void Main(
            string[] args)
        {
            var system       = (ExtendedActorSystem)ActorSystem.Create("StreamTcpClient");
            var materializer = system.Materializer();
            var connection   = new TcpExt(system).OutgoingConnection(address,
                                                                     port);

            var flow = Flow.Create <ByteString>()
                       .Via(Framing.Delimiter(ByteString.FromString("\n"),
                                              256,
                                              true))
                       .Via(Flow.Create <ByteString>()
                            .Select(bytes =>
            {
                var message = Encoding.UTF8.GetString(bytes.ToArray());
                _logger.Info(message);
                return(message);
            }))
                       .Via(Flow.Create <string>()
                            .Select(s => "Hello World"))
                       .Via(Flow.Create <string>()
                            .Select(s => s += "\n"))
                       .Via(Flow.Create <string>()
                            .Select(ByteString.FromString));

            connection.Join(flow)
            .Run(materializer);

            Console.ReadKey();
        }
Пример #2
0
        public TcpServer(
            string address,
            int port,
            ActorMaterializer materializer,
            ExtendedActorSystem system)
        {
            Address      = address;
            Port         = port;
            Materializer = materializer;
            System       = system;

            Connections = new TcpExt(System).Bind(Address,
                                                  Port);
        }