Created
March 13, 2014 10:57
-
-
Save oberstet/9526288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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