GrandTabernacleAutoVI/server/testsite/app.js
2023-12-06 08:56:09 +01:00

26 lines
629 B
JavaScript

const socket = new WebSocket('ws://localhost:8080?name=coucou'); //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'
}
}));
}