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
| return { | |
| main: function () { | |
| http.createServer(new_client).listen(listen_port); | |
| sys.puts("Listening on " + listen_port); | |
| } | |
| }; |
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
| function handle_couch_get(url, in_request, in_response) { | |
| sys.puts("Making outbound CouchDB request: " + sys.inspect(url)); | |
| var out_request = http.createClient(couch_port, couch_hostname) | |
| .request("GET", url.href, { | |
| "Host": couch_hostname | |
| }); | |
| out_request.addListener("response", function (out_response) { | |
| in_response.sendHeader(out_response.statusCode, out_response.headers); | |
| out_response.addListener("data", function (chunk) { | |
| in_response.write(chunk); |
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
| var sys = require('sys'), | |
| http = require('http'), | |
| pool = []; | |
| function finishTHEM(message){ | |
| var pool_size = pool.length, local_r, i; | |
| sys.puts("Sending " + message + " to " + pool_size + " clients."); | |
| for(i = 0; i < pool_size; i += 1) { | |
| local_r = pool.shift(); |
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
| function handle_couch_get(url, in_request, in_response) { | |
| sys.puts(in_request.connection.remoteAddress + " CouchDB request: " + sys.inspect(url)); | |
| var out_request = http.createClient(couch_port, couch_hostname) | |
| .request("GET", url.href, { | |
| "Host": couch_hostname | |
| }); | |
| out_request.addListener("response", function (out_response) { | |
| in_response.sendHeader(out_response.statusCode, out_response.headers); | |
| out_response.addListener("data", function (chunk) { | |
| in_response.write(chunk); |
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
| var sys = require("sys"), | |
| net = require("net"), | |
| repl = require("repl"); | |
| nconnections = 0; | |
| net.createServer(function (c) { | |
| sys.error("Connection!"); | |
| nconnections += 1; | |
| c.close(); | |
| }).listen(5000); |
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
| // setInterval / clearInterval | |
| var sys = require("sys"), | |
| start = new Date(), | |
| count = 10, | |
| timer = setInterval(function () { | |
| count -= 1; | |
| sys.puts("Timer fired after " + (Date.now() - start) + "ms " + count + " remaining."); | |
| if (count === 0) { | |
| clearInterval(timer); | |
| } |
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
| (in window 1) | |
| rv-mjr2:~$ node repltest.js | |
| node via stdin> foo | |
| 'stdin is fun' | |
| (in window 2) | |
| rv-mjr2:~$ telnet localhost 5000 | |
| Trying ::1... |
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
| var fs = require('fs'), | |
| sys = require('sys'); | |
| fs.stat("/tmp", function(err, stat_data) { | |
| if (err !== null) { | |
| sys.puts(err.stack); | |
| } | |
| else { | |
| sys.puts(sys.inspect(stat_data)); | |
| } |
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
| var sys = require('sys'), | |
| http = require('http'); | |
| http.createServer(function (req, res) { | |
| setTimeout(function () { | |
| res.writeHead(200, {'Content-Type': 'text/plain'}); | |
| res.write('Hello World'); | |
| res.close(); | |
| }, 2000); | |
| }).listen(8000); |
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
| var sys = require("sys"), | |
| http = require("http"), | |
| port = 12345, | |
| spawn = require("child_process").spawn; | |
| function gzipStr (str, callback) { | |
| var child = spawn("gzip", ["-c", "-f", "-n"]), | |
| stdout = "", stderr = ""; | |
| child.stdout.addListener("data", function (chunk) { |
OlderNewer