I am experimenting with client-server applications using the System.Net namespace in C#. I am currently using the following TcpListener code to listen for incoming connections:
TcpListener listener = new TcpListener(IPAddress.Any, 62126);
List<Connection> ClientConnections = new List<Connection>();
while (true)
{
listener.Start();
while (true)
{
if (listener.Pending())
{
ClientConnections.Add(new Connection(listener.AcceptTcpClient()));
break;
}
}
}
(Where Connection is a class that takes the accepted TcpClient via public Connection(TcpClient client) { ... }
and maintains the connection on a separate thread.)
Do I need to invoke listener.Start()
every time an incoming connection is accepted or is that unnecessary?