/// <summary> /// Establishes a connection to a remote host. /// </summary> /// <param name="socket">The socket that will create the connection.</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/bb538102.aspx">Socket.ConnectAsync</seealso> public static IObservable <SocketAsyncEventArgs> ConnectObservable(this Socket socket, SocketAsyncEventArgs eventArgs) { Contract.Requires(socket != null); Contract.Requires(eventArgs != null); Contract.Ensures(Contract.Result <IObservable <SocketAsyncEventArgs> >() != null); return(eventArgs.InvokeAsync(socket.ConnectAsync)); }
/// <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))); }
/// <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); }
/// <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); }
/// <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)); }