// gopher.js - a gopher implementation using node.js // Released under the 3 clause BSD license by Matt Croydon (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');