Got socket.on working

This commit is contained in:
Jacob Windle 2019-01-24 20:43:49 -05:00
parent 99dcd841ed
commit ea45d63909

View File

@ -1,19 +1,30 @@
var net = require('net'); var net = require('net');
/**
* Log the request and forward it.
* @param {String} bytes
*/
async function logAndSend(bytes) { async function logAndSend(bytes) {
console.log(bytes)
} }
var server = net.createServer((socket) => { var server = net.createServer((socket) => {
socket.on('end', (c) => { socket.on('end', (c) => {
console.log("Client disconnected"); console.log("Client disconnected");
}); });
socket.on("data", (c) => {
logAndSend(c.toString());
});
}) })
server.on('connection', () => { server.on('connection', (c) => {
console.log("Client connected!"); console.log("Client connected!" + c.read(10));
}); });
server.on("listening", (c) => {
console.log("LISTENING");
})
server.listen(8124, () => { server.listen(8124, () => {
console.log("Server bound."); console.log("Server bound.");
}) })