'Does it possible to handle or to recive data on client from websocket every 3s. of course this example doesnt work

I tried to do it this way, but of course, it doesn't work

this.connection.onmessage = event => {
                    setInterval(() => {
                      console.log(event.data)
                    }, 3000)
                  }


Solution 1:[1]

A Websocket is designed to be event driven.

When the server sends data to your client, the onmessage event runs. What you have done with this code, is to tell client to output the message received from the server every 3 seconds, every time a message is received.

To output data every 3 seconds, the data should be sent every 3 seconds otherwise you are missing the point of Websockets.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dutchman