Created
August 2, 2010 18:33
-
-
Save ricardobeat/505087 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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