.NET core replacement for TcpClient

2020-04-02 09:29发布

So in the old .NET you were able to initialize a new instance of the TcpClient class and connect to the specified port on the specified host using TcpClient(string, int). That no longer works for TcpClient in .NET core and I'm wondering if there is a replacement or some other way to do the same thing in core. I read the documentation, but maybe I'm missing something or there is a new, better way of going about this.

Also I'm going to use the GetStream method that works for both versions of TcpClient to load the stream into a NetworkStream.

标签: c# .net-core
1条回答
放我归山
2楼-- · 2020-04-02 09:53

As per the source code, you can connect with:

 public Task ConnectAsync(IPAddress address, int port)

Or one of the overloads.

And the GetStream you need, at line 151:

public NetworkStream GetStream()
查看更多
登录 后发表回答