const socket = new WebSocket('ws://localhost:8080'); //ws://129.151.227.50:9600 var time = new Date(); socket.addEventListener('open', (event) => { console.log('connecté'); }); socket.addEventListener('message', (event) => { document.getElementById("dtime").innerHTML = (new Date()-time).toString() + "ms"; console.log(event.data); }); socket.addEventListener('close', (event) => { console.log('Connexion au serveur WebSocket fermée'); }); function main(){ time = new Date() socket.send(JSON.stringify({ type: "update", data: { ok: 'ok' } })); }