Home » Javascript » javascript – Is it possible to loop ws.send?

javascript – Is it possible to loop ws.send?

Posted by: admin February 24, 2020 Leave a comment

Questions:

I wonder if it’s possible loop ws.send and make it send a response each 8 seconds.

ws.send('000f{"func":"ping"}');
How to&Answers:
setInterval(()=> ws.send('000f{"func":"ping"}'), 8000)

If you are using ES5:

setInterval(function (){ ws.send('000f{"func":"ping"}') }, 8000))