本文整理汇总了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);
});
}