-
Notifications
You must be signed in to change notification settings - Fork 1k
Ten second tutorial
Joe Walnes edited this page Jul 11, 2014
·
12 revisions
This is a really quick run through of getting a WebSocket application up and running with websocketd
. Quick, only eight seconds left!
No time now! Do it later.
We'll use bash. But you can use any language you like. websocketd has been used to create servers in Python, R, C, C#, AppleScript, PHP, pretty much anything (though I don't recommend JVM based languages).
count.sh:
#!/bin/bash
# Count from 1 to 10, pausing for a second between each iteration.
for COUNT in $(seq 1 10); do
echo $COUNT
sleep 1
done
Make it executable:
$ chmod +x ./count.sh
$ websocketd --port=8080 ./count.sh
In a web-page:
var ws = new WebSocket('ws://localhost:8080/');
ws.onmessage = function(event) {
console.log('Count is: ' + event.data);
};
Ok, got it?
Wanna learn more? Read the slightly more verbose ten MINUTE tutorial instead.
The websocketd user guide is a publicly editable wiki. Please contribute!
Getting Started
Reference
Language specific
Advanced: Internals
Spanish Websocket Wiki
Primeros pasos
Referencia
Lenguajes
Avanzado