Skip to content

Instantly share code, notes, and snippets.

@asergeyev
Created March 4, 2015 13:00
Show Gist options
  • Save asergeyev/a33f0f595ff551a5b8d3 to your computer and use it in GitHub Desktop.
Save asergeyev/a33f0f595ff551a5b8d3 to your computer and use it in GitHub Desktop.
Websocketd Greeter HTML
<!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>
@njamescouk
Copy link

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=.

@BigSully
Copy link

BigSully commented Jan 29, 2021

@njamescouk Indeed, the author didn't mention the script. Here is the greeter

@njamescouk
Copy link

it lives!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment