window.WebSocket=(window.WebSocket||window.MozWebSocket); var websocket=new WebSocket('ws://192.168.1.111:9000','myprotocol'); websocket.binaryType = 'arraybuffer'; //On utilise un objet arraybuffer pour envoyer les donnée. websocket.onopen=function(){ $('h3 .connecOn').css('color','green'); }; websocket.onerror=function(){ $('h3 .connecOff').css('color','red'); }; //on créé le tableau des octets à envoyer: var requete = new Uint8ClampedArray(3); requete[0] = 'G'.charCodeAt(0); requete[1] = 'E'.charCodeAt(0); requete[2] = 'T'.charCodeAt(0); //affiche le contenu du tableau dans une alert //alert(String.fromCharCode(reponseView.getUint8(0))+String.fromCharCode(reponseView.getUint8(1))+String.fromCharCode(reponseView.getUint8(2))); websocket.onmessage=function(message){ //Evenement surveillant la reception de message var reponse = new Uint8Array(message.data); console.dir(message.data); $('#relevesMeteo .temperature').text(reponse[0]); $('#relevesMeteo .humidite').text(reponse[1]); $('#relevesMeteo .pression').text(reponse[2]); //$('#relevesMeteo .luminosite').text(message.data);*/ }; function requeteEnvoi(){ websocket.send(requete.buffer); } //setInterval(requeteEnvoi,1000);