Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET core replacement for TcpClient

Tags:

c#

.net-core

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.

like image 387
hereswilson Avatar asked Jul 29 '16 13:07

hereswilson


People also ask

What is tcpclient in Java?

The TcpClient class provides simple methods for connecting, sending, and receiving stream data over a network in synchronous blocking mode. In order for TcpClient to connect and exchange data, a TcpListener or Socket created with the TCP ProtocolType must be listening for incoming connection requests.

What is the difference between the TCP server and TCP client?

The CLI and Host classes for the TCP Client is practically identical to the TCP Server, the full version is attached and downloadable.

What is the use of tcplistener and tcpclient objects?

To summarize, the service uses TcpListener and TcpClient objects to hide the complexity of raw socket programming, and uses the new AcceptTcpClientAsync method in conjunction with the new async and await keywords to hide the complexity of asynchronous programming.

Is DotNet core performance on top of other platforms?

Every time TCP Server developed using .Net Core was on top in performance as compared to other platforms. So no one should have doubt on .Net Core Performance. I would also like to share a comment on one of your post which was related to handling thousands of requests using Java The above comment describes the Dotnet Core Performance over rxjava.


1 Answers

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()
like image 57
Bruno Garcia Avatar answered Oct 11 '22 00:10

Bruno Garcia