Is it possible to send message to all client with tcp listener?
The answer is NO.
You use a socket server just for wait the new connections (Listener) and accept them. Each time that a socket server accept a new connection it assigns an independent socket client to attend the remote endpoint.
while (keepRunning)
{
try
{
TcpClient socket = server.AcceptTcpClient(); //Socket Server accept a new connection and assigned an independent socket client.
if (keepRunning)
RequestManager.askForRequestAdnRunIt(socket, idLayout); //The Socket Client is attending at the remote endpoint
}
catch (Exception ex)
{
log.Error("Se detecto un error en el puerto para atencion de peticiones. ERR: " + ex.Message);
log.Error(ex.StackTrace);
}
}
So, if you want to send a message to all the TCPClients sockets, you must send it one by one, i suggest send it by a Asynchronous method to improve the performance and avoid bottlenecks. Check this answer of mine to see how to send with asynchronous methods.