Skip to content

Instantly share code, notes, and snippets.

@ricardobeat
Created August 2, 2010 18:33
Show Gist options
  • Save ricardobeat/505087 to your computer and use it in GitHub Desktop.
Save ricardobeat/505087 to your computer and use it in GitHub Desktop.
http = new Server(8001);
function read(client) //returns true when a command is ready
{
var msg = ""
while (client.canRead)
{
let c = client.read(1)
if (!c.length) return false //dead connection
if (c == '\r') continue
if (c == '\n') return msg;
else msg += c;
}
return false;
}
writeln('running');
Clients = [];
running = true
while (running){
system.gc()
Clients.forEach(function(client){
if (msg = read(client))
writeln( msg );
});
if (!http.anyoneWaiting)
{
sleep(100);
continue;
}
var client = http.accept();
if (client == null)
continue;
Clients.push( client );
writeln('client accepted');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment