Exemple #1
0
 /// <summary>
 /// Creates a <see cref="Tcp.ServerBinding"/> instance which represents a prospective TCP server binding on the given <paramref name="host"/> and <paramref name="port"/>/>
 /// handling the incoming connections using the provided Flow.
 /// <para/>
 /// Please note that the startup of the server is asynchronous, i.e. after materializing the enclosing
 /// <see cref="RunnableGraph{TMat}"/> the server is not immediately available. Only after the materialized future
 /// completes is the server ready to accept client connections.
 /// </summary>
 /// <param name="handler">A Flow that represents the server logic</param>
 /// <param name="materializer">TBD</param>
 /// <param name="host">The host to listen on</param>
 /// <param name="port">The port to listen on</param>
 /// <param name="backlog">Controls the size of the connection backlog</param>
 /// <param name="options">TCP options for the connections, see <see cref="Akka.IO.Tcp"/> for details</param>
 /// <param name="halfClose">Controls whether the connection is kept open even after writing has been completed to the accepted TCP connections.
 /// If set to true, the connection will implement the TCP half-close mechanism, allowing the client to
 /// write to the connection even after the server has finished writing. The TCP socket is only closed
 /// after both the client and server finished writing.
 /// If set to false, the connection will immediately closed once the server closes its write side,
 /// independently whether the client is still attempting to write. This setting is recommended
 /// for servers, and therefore it is the default setting.
 /// </param>
 /// <param name="idleTimeout">TBD</param>
 /// <returns>TBD</returns>
 public Task <Tcp.ServerBinding> BindAndHandle(Flow <ByteString, ByteString, NotUsed> handler, IMaterializer materializer, string host, int port, int backlog = 100,
                                               IImmutableList <Inet.SocketOption> options = null, bool halfClose = false, TimeSpan?idleTimeout = null)
 {
     return(Bind(host, port, backlog, options, halfClose, idleTimeout)
            .To(Sink.ForEach <Tcp.IncomingConnection>(connection => connection.Flow.Join(handler).Run(materializer)))
            .Run(materializer));
 }
Exemple #2
0
 /// <summary>
 /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a foreach procedure. The given procedure is invoked
 /// for each received element.
 /// The returned <see cref="Task"/> will be completed with Success when reaching the
 /// normal end of the stream, or completed with Failure if there is a failure signaled in
 /// the stream.
 /// </summary>
 /// <param name="action">TBD</param>
 /// <param name="materializer">TBD</param>
 /// <returns>TBD</returns>
 public Task RunForeach(Action <TOut> action, IMaterializer materializer)
 => RunWith(Sink.ForEach(action), materializer);