Which .Net component should be used to communicate tcp / ip sockets?

We need to talk to another system that wants to contact us through raw tcp / ip socket communication. What would be the appropriate .Net object, if any, to use for this?

If you know about a third-party component, an open source component, etc. that you think is better to use, feel free to mention this as well.

+3
source share
5 answers

I would use TcpClient. It sits on top of Socket and is an abstraction on Socket. TcpClient has a GetStream that returns a Stream object. Then, to read a stream, you can simply use a stream reader.

For example:

tcpClient = new TcpClient(host, port)
                            {
                                ReceiveTimeout = readTimeout
                            };
            stream = tcpClient.GetStream();
            streamReader = new StreamReader(stream, Encoding.ASCII);
            streamWriter = new StreamWriter(stream, Encoding.ASCII)
                               {
                                   AutoFlush = true
                               };

            return this;

What allows (snippet):

s treamReader.Read(myReadBuffer, 0, myReadBuffer.Length)

+8
source

Dart Socket.net, system.net.sockets.socket /, . . , , , /.

Dart.com http://www.dart.com/ptsknet.aspx

+2

TcpClient , Socket. .

+1

Socket TCPClient . , . .

, . , async , . / .NET- , . , , - . "SocketException" , , . , SocketException, .

, , " " .

+1

Source: https://habr.com/ru/post/1714653/


All Articles