本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.InvokeAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.InvokeAsync方法的具体用法?C# SocketAsyncEventArgs.InvokeAsync怎么用?C# SocketAsyncEventArgs.InvokeAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.SocketAsyncEventArgs
的用法示例。
在下文中一共展示了SocketAsyncEventArgs.InvokeAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisconnectObservable
/// <summary>
/// Closes the socket connection and allows reuse of the <paramref name="socket"/>.
/// </summary>
/// <param name="socket">The socket that will be disconnected.</param>
/// <param name="eventArgs">The <see cref="SocketAsyncEventArgs"/> object to use for this asynchronous socket operation.</param>
/// <returns>A singleton observable sequence containing the result of the operation.</returns>
/// <seealso href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.disconnectasync.aspx">Socket.DisconnectAsync</seealso>
public static IObservable<SocketAsyncEventArgs> DisconnectObservable(this Socket socket, SocketAsyncEventArgs eventArgs)
{
Contract.Requires(socket != null);
Contract.Requires(eventArgs != null);
Contract.Ensures(Contract.Result<IObservable<SocketAsyncEventArgs>>() != null);
return eventArgs.InvokeAsync(socket.DisconnectAsync);
}
示例2: ReceiveMessageFromObservable
/// <summary>
/// Receives data from a bound <see cref="Socket"/>.
/// </summary>
/// <param name="socket">The socket that will receive the data.</param>
/// <param name="eventArgs">The <see cref="SocketAsyncEventArgs"/> object to use for this asynchronous socket operation.</param>
/// <returns>A singleton observable sequence containing the result of the operation.</returns>
/// <seealso href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receivemessagefromasync.aspx">Socket.ReceiveMessageFromAsync</seealso>
public static IObservable<SocketAsyncEventArgs> ReceiveMessageFromObservable(this Socket socket, SocketAsyncEventArgs eventArgs)
{
Contract.Requires(socket != null);
Contract.Requires(eventArgs != null);
Contract.Ensures(Contract.Result<IObservable<SocketAsyncEventArgs>>() != null);
return eventArgs.InvokeAsync(socket.ReceiveMessageFromAsync);
}
示例3: Connect
/// <summary>
/// Establishes a connection to a remote host.
/// </summary>
/// <param name="socketType">One of the <see cref="SocketType"/> values.</param>
/// <param name="protocolType">One of the <see cref="ProtocolType"/> values.</param>
/// <param name="eventArgs">The <see cref="SocketAsyncEventArgs"/> object to use for this asynchronous socket operation.</param>
/// <returns>A singleton observable sequence containing the result of the operation.</returns>
/// <seealso href="http://msdn.microsoft.com/en-us/library/cc422500.aspx">Socket.ConnectAsync</seealso>
public static IObservable<SocketAsyncEventArgs> Connect(
SocketType socketType,
ProtocolType protocolType,
SocketAsyncEventArgs eventArgs)
{
Contract.Requires(eventArgs != null);
Contract.Ensures(Contract.Result<IObservable<SocketAsyncEventArgs>>() != null);
return eventArgs.InvokeAsync(e => Socket.ConnectAsync(socketType, protocolType, e));
}