diff --git a/client.js b/client.js new file mode 100644 index 0000000..355e037 --- /dev/null +++ b/client.js @@ -0,0 +1,28 @@ +var net = require('net'); + +var CONFIG = require('./config'); + +var socket = new net.Socket(); + +var client = socket.connect({ port: CONFIG.PORT }, function() { + + var clientAddress = client.address().address; + var clientPort = client.address().port; + console.log("CONNECTED TO: " + clientAddress + ":" + CONFIG.PORT); + + process.stdin.on('data', function(data) { + client.write(clientAddress + ":" + clientPort + ': "' + data + '"'); + }); + + //socket.pipe(socket); + + //client.end(); + client.on('data', function(data) { + console.log(data.toString()); + }); + + client.on('end', function() { + console.log("You have logged off:)"); + client.end("you have logged off:)"); + }); +}); diff --git a/config.json b/config.json new file mode 100644 index 0000000..a698de7 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "PORT": 6969 +} \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..a47835f --- /dev/null +++ b/server.js @@ -0,0 +1,44 @@ +var net = require('net'); + +var CONFIG = require('./config'); + +var listOfClients = []; + +//Connection listener +var server = net.createServer(function (socket) { + //Connection listener + var clientAddress = socket.remoteAddress.slice(7); + var clientPort = socket.remotePort; + listOfClients.push(socket); + + console.log("CONNECTED: " + clientAddress + ":" + clientPort); + + socket.on('end', function() { + console.log("CLOSED: " + clientAddress + clientPort); + }); + + process.stdin.on('data', function(data) { + socket.write("[ADMIN]" + ' "' + data + '"'); + // if(socket.write() === "kick") { + // socket.end(); + // } + }); + + socket.on('data', function(data) { + console.log("SERVER BCAST FROM " + data); + + listOfClients.forEach(function(client) { + client.write(data); + }); + }); + //socket.pipe(socket); +}); + +server.listen(CONFIG.PORT, function () { + var PORT = server.address().port; + console.log('Server listening on', PORT); +}); + +server.on('error', function (err) { + console.log(err); +});