/// <summary> /// Establishes a connection to a remote host. /// </summary> /// <param name="addressFamily">One of the <see cref="AddressFamily"/> values.</param> /// <param name="socketType">One of the <see cref="SocketType"/> values.</param> /// <param name="protocolType">One of the <see cref="ProtocolType"/> values.</param> /// <param name="remoteEndPoint">An <see cref="EndPoint"/> that represents the remote host.</param> /// <returns>A singleton observable sequence containing the connected <see cref="Socket"/>.</returns> public static IObservable<Socket> Connect( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, EndPoint remoteEndPoint) { Contract.Requires(remoteEndPoint != null); Contract.Ensures(Contract.Result<IObservable<Socket>>() != null); var socket = new Socket(addressFamily, socketType, protocolType); return socket.ConnectObservable(remoteEndPoint).Select(_ => socket); }
/// <summary> /// Establishes a connection to a remote host. /// </summary> /// <param name="addressFamily">One of the <see cref="AddressFamily"/> values.</param> /// <param name="socketType">One of the <see cref="SocketType"/> values.</param> /// <param name="protocolType">One of the <see cref="ProtocolType"/> values.</param> /// <param name="remoteEndPoint">An <see cref="EndPoint"/> that represents the remote host.</param> /// <returns>A singleton observable sequence containing the connected <see cref="Socket"/>.</returns> public static IObservable <Socket> Connect( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, EndPoint remoteEndPoint) { Contract.Requires(remoteEndPoint != null); Contract.Ensures(Contract.Result <IObservable <Socket> >() != null); var socket = new Socket(addressFamily, socketType, protocolType); return(socket.ConnectObservable(remoteEndPoint).Select(_ => socket)); }
public static IObservable <Unit> ConnectObservable(this Socket socket, EndPoint remoteEndPoint) { Contract.Requires(socket != null); Contract.Requires(remoteEndPoint != null); Contract.Ensures(Contract.Result <IObservable <Unit> >() != null); var args = new SocketAsyncEventArgs() { RemoteEndPoint = remoteEndPoint }; return(socket .ConnectObservable(args) .Select(_ => Unit.Default) .Finally(args.Dispose)); }
/// <summary> /// Establishes a connection to a remote host. /// </summary> /// <param name="addressFamily">One of the <see cref="AddressFamily"/> values.</param> /// <param name="socketType">One of the <see cref="SocketType"/> values.</param> /// <param name="protocolType">One of the <see cref="ProtocolType"/> values.</param> /// <param name="address">The <see cref="IPAddress"/> of the remote host.</param> /// <param name="port">The port number of the remote host.</param> /// <returns>A singleton observable sequence containing the connected <see cref="Socket"/>.</returns> public static IObservable<Socket> Connect( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, IPAddress address, int port) { Contract.Requires(address != null); Contract.Requires(port >= IPEndPoint.MinPort); Contract.Requires(port <= IPEndPoint.MaxPort); Contract.Ensures(Contract.Result<IObservable<Socket>>() != null); var socket = new Socket(addressFamily, socketType, protocolType); return socket.ConnectObservable(address, port).Select(_ => socket); }
/// <summary> /// Establishes a connection to a remote host. /// </summary> /// <param name="addressFamily">One of the <see cref="AddressFamily"/> values.</param> /// <param name="socketType">One of the <see cref="SocketType"/> values.</param> /// <param name="protocolType">One of the <see cref="ProtocolType"/> values.</param> /// <param name="host">The name of the remote host.</param> /// <param name="port">The port number of the remote host.</param> /// <returns>A singleton observable sequence containing the connected <see cref="Socket"/>.</returns> public static IObservable <Socket> Connect( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, string host, int port) { Contract.Requires(host != null); Contract.Requires(port >= IPEndPoint.MinPort); Contract.Requires(port <= IPEndPoint.MaxPort); Contract.Ensures(Contract.Result <IObservable <Socket> >() != null); var socket = new Socket(addressFamily, socketType, protocolType); return(socket.ConnectObservable(host, port).Select(_ => socket)); }
public static IObservable <Unit> ConnectObservable(this Socket socket, IPAddress address, int port) { Contract.Requires(socket != null); Contract.Requires(address != null); Contract.Requires(port >= IPEndPoint.MinPort); Contract.Requires(port <= IPEndPoint.MaxPort); Contract.Ensures(Contract.Result <IObservable <Unit> >() != null); var args = new SocketAsyncEventArgs() { RemoteEndPoint = new IPEndPoint(address, port) }; return(socket .ConnectObservable(args) .Select(_ => Unit.Default) .Finally(args.Dispose)); }