Created
March 4, 2015 13:00
-
-
Save asergeyev/a33f0f595ff551a5b8d3 to your computer and use it in GitHub Desktop.
Websocketd Greeter HTML
This file contains hidden or 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> | |
<head> | |
<title>websocketd greeter example</title> | |
<style> | |
#messages { | |
font: bold 2em arial; | |
margin: auto; | |
padding: 10px; | |
text-align: center; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="messages"></div> | |
<div><input id="words"><button id="send">Send</button></div> | |
<script> | |
var ws = new WebSocket('ws://localhost:8080/'); | |
ws.onopen = function() { | |
document.body.style.backgroundColor = '#cfc'; | |
}; | |
ws.onclose = function() { | |
document.body.style.backgroundColor = null; | |
}; | |
ws.onmessage = function(event) { | |
document.getElementById('messages').textContent = event.data; | |
}; | |
document.getElementById('send').addEventListener("click", function(){ | |
ws.send(document.getElementById('words').value); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm missing some basic concept(s) wrt to websocketd. what is the websocketd command line on the server greeter.html connects to?
I've got as far as
--port=8080 --dir=.