window.WebSocket=(window.WebSocket||window.MozWebSocket); var websocket=new WebSocket('ws://192.168.1.111:9000','myprotocol'); websocket.onopen=function(){ $('h3 .connecOn').css('color','green'); }; websocket.onerror=function(){ $('h3 .connecOff').css('color','red'); }; //on crée des tableaux de Buffer, ces tableaux permettent de "découper" la chaine de bits, en différents octets var bufferReponse = new ArrayBuffer(3); var bufferRequete = new ArrayBuffer(3); //DataView permet de traiter un ArrayBuffer var requeteView = new DataView(bufferRequete); var reponseView = new DataView(bufferReponse); //on remplie le buffer de requete via requeteView requeteView.setInt8(0,'G'.charCodeAt(0)); requeteView.setInt8(1,'E'.charCodeAt(0)); requeteView.setInt8(2,'T'.charCodeAt(0)); //affiche le contenu du tableau dans une alert alert(String.fromCharCode(requeteView.getInt8(0))+String.fromCharCode(requeteView.getInt8(1))+String.fromCharCode(requeteView.getInt8(2))); websocket.onmessage=function(message){ //Evenement surveillant la reception de message console.log(message.data); /*$('#relevesMeteo .temperature').text(message.data); $('#relevesMeteo .humidite').text(message.data); $('#relevesMeteo .pression').text(message.data); $('#relevesMeteo .luminosite').text(message.data);*/ }; function requeteEnvoi(){ websocket.send(bufferReponse); console.log(bufferReponse); } //setInterval(requeteEnvoi,1000);