Created
July 22, 2010 05:37
-
-
Save mcroydon/485609 to your computer and use it in GitHub Desktop.
This file contains 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
// gopher.js - a minimal gopher implementation using node.js | |
// Released under the 3 clause BSD license by Matt Croydon <[email protected]> (http://postneo.com) | |
var net = require('net'); | |
net.createServer(function (socket) { | |
socket.setEncoding("ascii"); | |
socket.on("data", function (data) { | |
if (data === '\r\n') { | |
console.log('Serving index.'); | |
socket.write('0About gopher.js' + '\t' + 'About' + '\t' + '127.0.0.1' + '\t' + '70'); | |
socket.write('.\r\n'); | |
socket.end(); | |
} | |
else if (data === 'About\r\n') { | |
console.log('Serving about file.'); | |
socket.write('Gopher.js is a minimal implementation of the gopher protocol using node.js.\r\n' + | |
'To try it for yourself, run "node gopher.js" and connect to gopher://127.0.0.1 using a gopher client or a browser like Firefox.\r\n' + | |
'You will likely need to run this command as root or with sudo.\r\n'); | |
socket.end(); | |
} | |
else { | |
console.log('Unknown: ' + data); | |
} | |
}); | |
socket.on("end", function () { | |
console.log('Ending connection.'); | |
socket.end(); | |
}); | |
}).listen(70, "127.0.0.1"); | |
console.log('Server running at 127.0.0.1:70'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment