Skip to content

Instantly share code, notes, and snippets.

@oberstet
Created March 13, 2014 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oberstet/9526288 to your computer and use it in GitHub Desktop.
Save oberstet/9526288 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<body>
<script>
function carre(){
ws = new WebSocket("ws://127.0.0.1:9000");
ws.onopen = function(){
console.log("Connection is open...");
// Web Socket is connected, send data using send()
val = document.getElementById("val").value;
var_json = '[2, "2262626262", "big", {"valeur" : ' + val + '}]';
ws.send(var_json);
console.log("json envoyé : " + var_json);
};
ws.onmessage = function (evt){
var received_msg = evt.data;
document.getElementById('carre').value = received_msg;
console.log("JSon reçu : " + received_msg);
};
ws.onclose = function(){
// websocket is closed.
console.log("Connection is closed...");
};
}
</script>
<p><input type="text" id="val" value="6"/><input type="button" OnClick="carre();" value="mettre au carre !"/></p>
<p>resultat du carre : <input type="text" id="carre" /></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment