当前位置: 首页>>代码示例>>C#>>正文


C# TcpListener.StartObservable方法代码示例

本文整理汇总了C#中System.Net.Sockets.TcpListener.StartObservable方法的典型用法代码示例。如果您正苦于以下问题:C# TcpListener.StartObservable方法的具体用法?C# TcpListener.StartObservable怎么用?C# TcpListener.StartObservable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Sockets.TcpListener的用法示例。


在下文中一共展示了TcpListener.StartObservable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    /// <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);
        });
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:30,代码来源:ObservableTcpListener.cs


注:本文中的System.Net.Sockets.TcpListener.StartObservable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。