Exemple #1
0
        /// <summary>
        /// Returns a BidiFlow that implements a simple framing protocol. This is a convenience wrapper over <see cref="LengthField"/>
        /// and simply attaches a length field header of four bytes (using big endian encoding) to outgoing messages, and decodes
        /// such messages in the inbound direction. The decoded messages do not contain the header.
        ///
        /// This BidiFlow is useful if a simple message framing protocol is needed (for example when TCP is used to send
        /// individual messages) but no compatibility with existing protocols is necessary.
        ///
        /// The encoded frames have the layout
        /// {{{
        ///     [4 bytes length field, Big Endian][User Payload]
        /// }}}
        /// The length field encodes the length of the user payload excluding the header itself.
        /// </summary>
        /// <param name="maximumMessageLength">Maximum length of allowed messages. If sent or received messages exceed the configured limit this BidiFlow will fail the stream. The header attached by this BidiFlow are not included in this limit.</param>
        /// <returns></returns>
        public static BidiFlow <ByteString, ByteString, ByteString, ByteString, NotUsed> SimpleFramingProtocol(int maximumMessageLength)
        {
            var decoder = LengthField(4, maximumMessageLength + 4, 0, ByteOrder.BigEndian).Select(b => b.Drop(4));
            var encoder = Flow.Create <ByteString>().Transform(() => new FramingDecoderStage(maximumMessageLength));

            return(BidiFlow.FromFlowsMat(encoder, decoder, Keep.Left));
        }
Exemple #2
0
        /// <summary>
        /// Creates a <see cref="Tcp.OutgoingConnection"/> instance representing a prospective TCP client connection to the given endpoint.
        /// <para>
        /// Note that the <see cref="ByteString"/> chunk boundaries are not retained across the network,
        /// to achieve application level chunks you have to introduce explicit framing in your streams,
        /// for example using the <see cref="Framing"/> stages.
        /// </para>
        /// </summary>
        /// <param name="remoteAddress"> The remote address to connect to</param>
        /// <param name="localAddress">Optional local address for the connection</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 server to
        /// write to the connection even after the client has finished writing.The TCP socket is only closed
        /// after both the client and server finished writing. This setting is recommended for clients and therefore it is the default setting.
        /// If set to false, the connection will immediately closed once the client closes its write side,
        /// independently whether the server is still attempting to write.
        /// </param>
        /// <param name="connectionTimeout">TBD</param>
        /// <param name="idleTimeout">TBD</param>
        /// <returns>TBD</returns>
        public Flow <ByteString, ByteString, Task <Tcp.OutgoingConnection> > OutgoingConnection(EndPoint remoteAddress, EndPoint localAddress = null,
                                                                                                IImmutableList <Inet.SocketOption> options    = null, bool halfClose = true, TimeSpan?connectionTimeout = null, TimeSpan?idleTimeout = null)
        {
            //connectionTimeout = connectionTimeout ?? TimeSpan.FromMinutes(60);

            var tcpFlow =
                Flow.FromGraph(new OutgoingConnectionStage(_system.Tcp(), remoteAddress, localAddress, options,
                                                           halfClose, connectionTimeout)).Via(new Detacher <ByteString>());

            if (idleTimeout.HasValue)
            {
                return(tcpFlow.Join(BidiFlow.BidirectionalIdleTimeout <ByteString, ByteString>(idleTimeout.Value)));
            }

            return(tcpFlow);
        }
Exemple #3
0
 /// <summary>
 /// Returns a BidiFlow that implements a simple framing protocol. This is a convenience wrapper over <see cref="LengthField"/>
 /// and simply attaches a length field header of four bytes (using big endian encoding) to outgoing messages, and decodes
 /// such messages in the inbound direction. The decoded messages do not contain the header.
 ///
 /// This BidiFlow is useful if a simple message framing protocol is needed (for example when TCP is used to send
 /// individual messages) but no compatibility with existing protocols is necessary.
 ///
 /// The encoded frames have the layout
 /// {{{
 ///     [4 bytes length field, Big Endian][User Payload]
 /// }}}
 /// The length field encodes the length of the user payload excluding the header itself.
 /// </summary>
 /// <param name="maximumMessageLength">Maximum length of allowed messages. If sent or received messages exceed the configured limit this BidiFlow will fail the stream. The header attached by this BidiFlow are not included in this limit.</param>
 /// <returns>TBD</returns>
 public static BidiFlow <ByteString, ByteString, ByteString, ByteString, NotUsed> SimpleFramingProtocol(int maximumMessageLength)
 {
     return(BidiFlow.FromFlowsMat(SimpleFramingProtocolEncoder(maximumMessageLength),
                                  SimpleFramingProtocolDecoder(maximumMessageLength), Keep.Left));
 }
Exemple #4
0
 public static BidiFlow <TIn, TIn, TOut, TOut, NotUsed> Apply <TIn, TOut>(int maxPending)
 {
     return(BidiFlow.FromGraph(new One2OneBidi <TIn, TOut>(maxPending)));
 }