Runtime: Missing `System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)` overload.

Created on 6 Oct 2020  路  9Comments  路  Source: dotnet/runtime

Background and Motivation

This issue proposes to add System.Net.Sockets.TcpClient.ConnectAsync(IPEndPoint remoteEP) method.

This issue was filed based on #40750 and comment https://github.com/dotnet/runtime/pull/40750#issuecomment-704112931 by @geoffkizer.

Proposed API

namespace System.Net.Sockets
public class TcpClient : IDisposable
{

    public void Connect(IPAddress address, int port);
    public void Connect(IPAddress[] ipAddresses, int port);
    public void Connect(IPEndPoint remoteEP);
    public void Connect(string hostname, int port);

    public Task ConnectAsync(IPAddress address, int port);
    public Task ConnectAsync(IPAddress[] addresses, int port);
+    public Task ConnectAsync(IPEndPoint remoteEP);
    public Task ConnectAsync(string host, int port);

    public ValueTask ConnectAsync (IPAddress address, int port, CancellationToken cancellationToken);
    public ValueTask ConnectAsync (IPAddress[] addresses, int port, CancellationToken cancellationToken);
+    public ValueTask ConnectAsync(IPEndPoint remoteEP,  CancellationToken cancellationToken);
    public ValueTask ConnectAsync (string host, int port, CancellationToken cancellationToken);
}

Usage Examples

Usage example is the same as for System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP).

Alternative Designs

N/A.

Risks

N/A

api-approved area-System.Net.Sockets

Most helpful comment

We would certainly also want the newer ValueTask-CancellationToken overload.

I assume the reason that overload was missed is because the non-cancellable overload was missing.

c# public ValueTask ConnectAsync(IPEndPoint remoteEP, CancellationToken cancellationToken);

All 9 comments

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

We would certainly also want the newer ValueTask-CancellationToken overload.

I assume the reason that overload was missed is because the non-cancellable overload was missing.

c# public ValueTask ConnectAsync(IPEndPoint remoteEP, CancellationToken cancellationToken);

Proposal updated in top post and marked as ready for review -- cc @scalablecory

I vaguely recall that we decided to leave this one off intentionally, but I could be misremembering.

This just seems like an oversight. We have a sync overload for this, but not async.

Video

  • Looks good as proposed

```C#
namespace System.Net.Sockets
{
public class TcpClient : IDisposable
{
//public void Connect(IPAddress address, int port);
//public void Connect(IPAddress[] ipAddresses, int port);
//public Task Connect(IPEndPoint remoteEP);
//public void Connect(string hostname, int port);

    //public Task ConnectAsync(IPAddress address, int port);
    //public Task ConnectAsync(IPAddress[] addresses, int port);
    //public Task ConnectAsync(string host, int port);
    public Task ConnectAsync(IPEndPoint remoteEP);

    //public ValueTask ConnectAsync(IPAddress address, int port, CancellationToken cancellationToken);
    //public ValueTask ConnectAsync(IPAddress[] addresses, int port, CancellationToken cancellationToken);
    //public ValueTask ConnectAsync(string host, int port, CancellationToken cancellationToken);
    public ValueTask ConnectAsync(IPEndPoint remoteEP, CancellationToken cancellationToken);
}

}
```

@MartyIX are you interested in submitting a PR?

@karelz I would kind of love to try but I don't have too much time lately on hand. So I would let it up-for-grabs.

Was this page helpful?
0 / 5 - 0 ratings