Created
May 21, 2011 00:24
-
-
Save kersny/984063 to your computer and use it in GitHub Desktop.
Pipe file to Socket
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'); | |
| var net = require('net'); | |
| var filename = 'pagerank.js'; | |
| var server = net.createServer(function(connection) { | |
| var stream = fs.createReadStream(filename); | |
| stream.pipe(connection); | |
| stream.on('end', function() { | |
| connection.end(); | |
| }); | |
| }); | |
| server.listen(1337); | |
| // telnet localhost 1337 | |
| // will show the contents of pagerank.js | |
| //~$ telnet localhost 1337 | |
| //Trying ::1... | |
| //telnet: connect to address ::1: Connection refused | |
| //Trying fe80::1... | |
| //telnet: connect to address fe80::1: Connection refused | |
| //Trying 127.0.0.1... | |
| //Connected to localhost. | |
| //Escape character is '^]'. | |
| //var util = require('util') | |
| // | |
| //num = 4; | |
| //pagerank = [.25,.25,.25,.25] | |
| //d = .15 | |
| //outbound = [3.0,1.0,2.0,2.0] | |
| //links = [[0,0,1,0],[1,0,0,1],[1,1,0,1],[1,0,1,0]] | |
| // | |
| //for (var x = 0; x < 100; x++) { | |
| // for (i=0; i<4; i++) { | |
| // var pr = (1.0 - d)/4.0; | |
| // var temp = 0; | |
| // for (j=0; j<4; j++) { | |
| // if (links[i][j] == 1) { | |
| // temp += pagerank[j]/outbound[j] | |
| // } | |
| // } | |
| // pr += d * temp; | |
| // pagerank[i] = pr | |
| // } | |
| //} | |
| // | |
| //console.log(util.inspect(pagerank)) | |
| //Connection closed by foreign host. | |
| //~$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment