public static IObservable <Socket> StartSocketObservable(this TcpListener listener, int maxConcurrent)
        {
            Contract.Requires(listener != null);
            Contract.Requires(maxConcurrent > 0);
            Contract.Ensures(Contract.Result <IObservable <Socket> >() != null);

            return(listener.StartObservable(
                       () => Observable.StartAsync(listener.AcceptSocketAsync),
                       maxConcurrent));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns an observable of concurrent TCP connections.  (See the remarks section for important details about the concurrent behavior.)
        /// </summary>
        /// <remarks>
        /// <alert type="warning">
        /// <see cref="Start(IPEndPoint)"/> returns an observable that may send notifications concurrently.  This behavior allows
        /// observers to receive multiple clients concurrently, as is common in hosting scenarios; however, it violates an important contract
        /// in Rx.  The Rx Design Guidelines document states that Rx operators assume notifications are sent in a serialized fashion.  The only
        /// methods that do not conflict with this guideline and are safe to call on the observable that is returned by
        /// <see cref="Start(IPEndPoint)"/> are <strong>Subscribe</strong> and <strong>Synchronize</strong>.  Do not attempt to use
        /// any other Rx operators unless the observable is synchronized first.
        /// </alert>
        /// </remarks>
        /// <param name="address">The local IP address on which to listen for clients.</param>
        /// <param name="port">The local port number on which to listen for clients.</param>
        /// <param name="maxConcurrent">The maximum number of clients that can be pushed through the observable simultaneously.</param>
        /// <returns>An observable of concurrent TCP connections.</returns>
        public static IObservable <TcpClient> Start(IPAddress address, int port, int maxConcurrent)
        {
            Contract.Requires(address != null);
            Contract.Requires(port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort);
            Contract.Ensures(Contract.Result <IObservable <TcpClient> >() != null);

            return(Observable.Defer(() =>
            {
                var listener = new TcpListener(address, port);

                return listener.StartObservable(maxConcurrent).Finally(listener.Stop);
            }));
        }
Esempio n. 3
0
    /// <summary>
    /// Returns an observable of concurrent TCP connections.  (See the remarks section for important details about the concurrent behavior.)
    /// </summary>
    /// <remarks>
    /// <alert type="warning">
    /// <see cref="Start(IPEndPoint)"/> returns an observable that may send notifications concurrently.  This behavior allows 
    /// observers to receive multiple clients concurrently, as is common in hosting scenarios; however, it violates an important contract 
    /// in Rx.  The Rx Design Guidelines document states that Rx operators assume notifications are sent in a serialized fashion.  The only 
    /// methods that do not conflict with this guideline and are safe to call on the observable that is returned by 
    /// <see cref="Start(IPEndPoint)"/> are <strong>Subscribe</strong> and <strong>Synchronize</strong>.  Do not attempt to use 
    /// any other Rx operators unless the observable is synchronized first.
    /// </alert>
    /// </remarks>
    /// <param name="address">The local IP address on which to listen for clients.</param>
    /// <param name="port">The local port number on which to listen for clients.</param>
    /// <param name="maxConcurrent">The maximum number of clients that can be pushed through the observable simultaneously.</param>
    /// <returns>An observable of concurrent TCP connections.</returns>
    public static IObservable<TcpClient> Start(IPAddress address, int port, int maxConcurrent)
    {
      Contract.Requires(address != null);
      Contract.Requires(port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort);
      Contract.Ensures(Contract.Result<IObservable<TcpClient>>() != null);

      return Observable.Defer(() =>
        {
          var listener = new TcpListener(address, port);

          return listener.StartObservable(maxConcurrent).Finally(listener.Stop);
        });
    }