Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -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:)");
});
});
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"PORT": 6969
}
44 changes: 44 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -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);
});