-
-
Save emceeaich/a3f73673c512582feb4e33c3831b815d 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 gopher implementation using node.js | |
// Released under the 3 clause BSD license by Matt Croydon <[email protected]> (http://postneo.com) | |
// Forked by Emma Humphries (https://emmah.net/) for stupid Internet of Things tricks | |
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.write('0Local Temperature' + '\t' + 'Temp' + '\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 if (data === 'Temp\r\n') { | |
console.log('Serving climate module data'); | |
socket.write('Local climate data here\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