#!/bin/bash
# Count from 1 to 10 with a sleep
for ((COUNT = 1; COUNT <= 10; COUNT++)); do
echo $COUNT
sleep 0.5
done
class Counter {
public static void main(String [] args) throws Exception {
for (int i=0; i<10; i++) {
System.out.println(i);
Thread.sleep(500);
}
}
}
#!/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)
#!/usr/bin/ruby
# Count from 1 to 10 with a sleep
STDOUT.sync = true
(1..10).each do |count|
puts count
sleep(0.5)
end
#!/usr/bin/php
<?php
# Count from 1 to 10 with a sleep
for ($count = 1; $count <= 10; $count++) {
echo $count . "\n";
usleep(500000);
}
?>
#!/usr/bin/perl
use Time::HiRes qw(sleep);
# Autoflush
$|++;
# Count from 1 to 10 with a sleep
for my $count (1 .. 10) {
print "$count\n";
sleep 0.5;
}
#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;
}
using System;
using System.Threading;
class Counter
{
static void Main()
{
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(500);
}
}
}
#!/usr/bin/env xcrun swift
import AppKit
for index in 1...10 {
print(index)
fflush(__stdoutp)
NSThread.sleepForTimeInterval(0.5)
}
import 'dart:io';
main() {
for (int i = 0; i < 10; i++) {
print(i);
sleep(const Duration(milliseconds: 500));
}
}
You get the idea!
If you can write a program that can be launched from
the command line, you can build a WebSocket server.
Read inbound messages from STDIN.
Write outbound messages to STDOUT.
Read HTTP and connection details from environment vars.
Use line breaks as message delimiters.