0

Is it possible to send message to all client with tcp listener?

Example:

TCP Listener running, Listener sending the default message to clients, client1 connect get the default message, client2 connect get the default message, if client1 or client2 modify the default message and send it to the listener then listener send the modified message to client1 and client2.

1
  • It is unclear what you are asking. TCP is a two-way communication so messages could of course be sent in both directions and checked by client as well as server side. Commented Dec 5, 2017 at 19:49

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.