Help choose Socket or TCPListener

I read the 2 source code of the C # chat, and I see the problem: One source uses the Socket class:

private void StartToListen(object sender , DoWorkEventArgs e)
{
    this.listenerSocket = new Socket(AddressFamily.InterNetwork , SocketType.Stream , ProtocolType.Tcp);
    this.listenerSocket.Bind(new IPEndPoint(this.serverIP , this.serverPort));
    this.listenerSocket.Listen(200);
    while ( true )
        this.CreateNewClientManager(this.listenerSocket.Accept());
}

And the other uses the TcpListener class:

    server = new TcpListener(portNumber);
    logger.Info("Server starts");
    while (true)
    {
        server.Start();
        if (server.Pending())
        {
            TcpClient connection = server.AcceptTcpClient();
            logger.Info("Connection made");
            BackForth BF = new BackForth(connection);
        }
    }

Please help me choose one. I have to use the Socket class or the TcpListener class. Socket connection - TCP or UDP? Thank.

+3
source share
1 answer

UDP , , . TCP - (, , ) ( , , , listen() ). UDP , , ( MTU, ).

, TCP, , , . , , , , , , ... "" , .

+4

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


All Articles