Awesome tool which turns any console application in WebSocket Server, whatever programming language you use.
Available for Windows, Linux, Mac
Try it, really awesome
#!/usr/bin/python
from sys import stdout
from time import sleep
# Count from 1 to 10 with a sleep
for count in range(0, 10):
print(count + 1)
stdout.flush()
sleep(0.5)
#!/bin/bash
# Count from 1 to 10 with a sleep
for ((COUNT = 1; COUNT <= 10; COUNT++)); do
echo $COUNT
sleep 0.5
done
using System;
using System.Threading;
class Counter
{
static void Main()
{
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(500);
}
}
}
#include <stdio.h>
#include <unistd.h>
int main() {
int i;
// Disable output buffering.
setbuf(stdout, NULL);
for (i = 1; i <= 10; i++) {
printf("%d\n", i);
usleep(500000);
}
return 0;
}
Launch the server with the following command
c:\> websocketd --port=8080 my-program
and in Javascript
var ws = new WebSocket('ws://localhost:8080/');
ws.onmessage = function(event) {
console.log('Count is: ' + event.data);
};