From 59bc6ec1a03f7e51204d80fedcac5d5f5e903da4 Mon Sep 17 00:00:00 2001 From: Christie R Date: Sat, 25 Jun 2016 18:11:40 -1000 Subject: [PATCH 1/8] Initial commit :D --- client.js | 0 server.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 client.js create mode 100644 server.js diff --git a/client.js b/client.js new file mode 100644 index 0000000..e69de29 diff --git a/server.js b/server.js new file mode 100644 index 0000000..e69de29 From 112a7cfbe20d6b33ef4bd960c6adae28599506cc Mon Sep 17 00:00:00 2001 From: Christie R Date: Sat, 25 Jun 2016 19:11:07 -1000 Subject: [PATCH 2/8] Basic connection --- client.js | 14 ++++++++++++++ config.json | 3 +++ server.js | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 config.json diff --git a/client.js b/client.js index e69de29..09898af 100644 --- a/client.js +++ b/client.js @@ -0,0 +1,14 @@ +var net = require('net'); + +var CONFIG = require('./config'); + +var socket = new net.Socket(); + +var client = socket.connect({ port: CONFIG.PORT }, function() { + console.log("YOU'RE IN THE SERVER!!!!!"); + +}); + +client.on('end', function() { + console.log("Logged off:)"); +}); \ No newline at end of file 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 index e69de29..48014d0 100644 --- a/server.js +++ b/server.js @@ -0,0 +1,18 @@ +var net = require('net'); + +var CONFIG = require('./config'); + +//Connection listener +var server = net.createServer(function (socket) { + //Connection listener + console.log("SOMEONE'S INSIDE:O :O "); +}); + +server.listen(CONFIG.PORT, function () { + var PORT = server.address().port; + console.log('This is working!:D Listening on port', PORT); +}); + +server.on('error', function (err) { + console.log(err); +}); \ No newline at end of file From 855f3f05059ad0a804b6253cd27d8963c1e9af74 Mon Sep 17 00:00:00 2001 From: Christie R Date: Sat, 25 Jun 2016 19:20:49 -1000 Subject: [PATCH 3/8] Can recognize when client is on or off server:) --- client.js | 2 +- server.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client.js b/client.js index 09898af..79dca82 100644 --- a/client.js +++ b/client.js @@ -6,7 +6,7 @@ var socket = new net.Socket(); var client = socket.connect({ port: CONFIG.PORT }, function() { console.log("YOU'RE IN THE SERVER!!!!!"); - + client.end(); }); client.on('end', function() { diff --git a/server.js b/server.js index 48014d0..cab952f 100644 --- a/server.js +++ b/server.js @@ -6,6 +6,14 @@ var CONFIG = require('./config'); var server = net.createServer(function (socket) { //Connection listener console.log("SOMEONE'S INSIDE:O :O "); + + socket.on('end', function() { + console.log("THEY'RE GONE"); + }); + + socket.write("hi"); + socket.pipe(socket); + }); server.listen(CONFIG.PORT, function () { @@ -15,4 +23,4 @@ server.listen(CONFIG.PORT, function () { server.on('error', function (err) { console.log(err); -}); \ No newline at end of file +}); From ca884a84b12d4c697dde70372dab725188c30e9d Mon Sep 17 00:00:00 2001 From: Christie R Date: Sat, 25 Jun 2016 19:24:31 -1000 Subject: [PATCH 4/8] I GOT THE MESSAGE FROM TEH SERVER --- client.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client.js b/client.js index 79dca82..9bf2f21 100644 --- a/client.js +++ b/client.js @@ -6,9 +6,14 @@ var socket = new net.Socket(); var client = socket.connect({ port: CONFIG.PORT }, function() { console.log("YOU'RE IN THE SERVER!!!!!"); - client.end(); -}); + //client.end(); + client.on('data', function(socket) { + console.log("Receiving informationnn:O"); + console.log(socket.toString()); + client.end(); + }); -client.on('end', function() { - console.log("Logged off:)"); -}); \ No newline at end of file + client.on('end', function() { + console.log("Logged off:)"); + }); +}); From 0c00d014311a98a2a2ef943101a96b7994989ca5 Mon Sep 17 00:00:00 2001 From: Christie R Date: Sat, 25 Jun 2016 19:31:07 -1000 Subject: [PATCH 5/8] I CAN RECEIVE MESSAGES BOTH WAYS --- client.js | 8 +++++--- server.js | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client.js b/client.js index 9bf2f21..0b4c5b0 100644 --- a/client.js +++ b/client.js @@ -6,11 +6,13 @@ var socket = new net.Socket(); var client = socket.connect({ port: CONFIG.PORT }, function() { console.log("YOU'RE IN THE SERVER!!!!!"); + client.write(" world :)"); + //client.end(); - client.on('data', function(socket) { + client.on('data', function(data) { console.log("Receiving informationnn:O"); - console.log(socket.toString()); - client.end(); + console.log(data.toString()); + //client.end(); }); client.on('end', function() { diff --git a/server.js b/server.js index cab952f..b860586 100644 --- a/server.js +++ b/server.js @@ -11,7 +11,13 @@ var server = net.createServer(function (socket) { console.log("THEY'RE GONE"); }); - socket.write("hi"); + socket.on('data', function(data) { + console.log("Receiving informationnn:O"); + console.log(data.toString()); + //client.end(); + }); + + socket.write("Hello"); socket.pipe(socket); }); From 85c9f37626f1c964d701124e22fda8d7903c447c Mon Sep 17 00:00:00 2001 From: Christie R Date: Sat, 25 Jun 2016 19:41:54 -1000 Subject: [PATCH 6/8] Need to figure out how to send messages back and forth:O --- client.js | 8 ++++---- server.js | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/client.js b/client.js index 0b4c5b0..63432ae 100644 --- a/client.js +++ b/client.js @@ -5,17 +5,17 @@ var CONFIG = require('./config'); var socket = new net.Socket(); var client = socket.connect({ port: CONFIG.PORT }, function() { - console.log("YOU'RE IN THE SERVER!!!!!"); - client.write(" world :)"); + console.log("You are logged in:)"); + client.write("\nMessage from client: 'World :)'"); //client.end(); client.on('data', function(data) { - console.log("Receiving informationnn:O"); + console.log("\nReceiving from server: "); console.log(data.toString()); //client.end(); }); client.on('end', function() { - console.log("Logged off:)"); + console.log("You have logged off:)"); }); }); diff --git a/server.js b/server.js index b860586..c8bb2d1 100644 --- a/server.js +++ b/server.js @@ -5,26 +5,27 @@ var CONFIG = require('./config'); //Connection listener var server = net.createServer(function (socket) { //Connection listener - console.log("SOMEONE'S INSIDE:O :O "); + console.log("\nA client logged in:)"); socket.on('end', function() { - console.log("THEY'RE GONE"); + console.log("\nA client has logged out."); }); + socket.write("\nMessage from server: 'Hello' "); + socket.pipe(socket); + + socket.on('data', function(data) { - console.log("Receiving informationnn:O"); + console.log("\nReceiving from client: "); console.log(data.toString()); + //socket.write("Data is: " + data); //client.end(); }); - - socket.write("Hello"); - socket.pipe(socket); - }); server.listen(CONFIG.PORT, function () { var PORT = server.address().port; - console.log('This is working!:D Listening on port', PORT); + console.log('You are in the server', PORT); }); server.on('error', function (err) { From 73939f78bd8773f973a9fc72a93fd3b67a40d81f Mon Sep 17 00:00:00 2001 From: Christie R Date: Wed, 29 Jun 2016 18:45:40 -1000 Subject: [PATCH 7/8] It looks like the example:D Need to add another client --- client.js | 10 ++++++---- server.js | 13 ++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/client.js b/client.js index 63432ae..e30a96e 100644 --- a/client.js +++ b/client.js @@ -5,17 +5,19 @@ var CONFIG = require('./config'); var socket = new net.Socket(); var client = socket.connect({ port: CONFIG.PORT }, function() { - console.log("You are logged in:)"); - client.write("\nMessage from client: 'World :)'"); + console.log("CONNECTED TO: " + CONFIG.PORT); + + process.stdin.on('data', function(data) { + client.write("SERVER BCAST FROM " + CONFIG.PORT + ": " + '"' + data + '"'); + }); //client.end(); client.on('data', function(data) { - console.log("\nReceiving from server: "); console.log(data.toString()); - //client.end(); }); client.on('end', function() { console.log("You have logged off:)"); + client.end(console.log("You have logged off:)")); }); }); diff --git a/server.js b/server.js index c8bb2d1..90e14db 100644 --- a/server.js +++ b/server.js @@ -5,27 +5,26 @@ var CONFIG = require('./config'); //Connection listener var server = net.createServer(function (socket) { //Connection listener - console.log("\nA client logged in:)"); + console.log("CONNECTED: " + CONFIG.PORT); socket.on('end', function() { - console.log("\nA client has logged out."); + console.log("\nCLOSED: " + CONFIG.PORT); }); - socket.write("\nMessage from server: 'Hello' "); socket.pipe(socket); + process.stdin.on('data', function(data) { + socket.write("HOST: " + data); + }); socket.on('data', function(data) { - console.log("\nReceiving from client: "); console.log(data.toString()); - //socket.write("Data is: " + data); - //client.end(); }); }); server.listen(CONFIG.PORT, function () { var PORT = server.address().port; - console.log('You are in the server', PORT); + console.log('Server listening on', PORT); }); server.on('error', function (err) { From 752e681999fdff7b7aae07b3a26648e598271c9a Mon Sep 17 00:00:00 2001 From: Christie R Date: Wed, 29 Jun 2016 21:52:05 -1000 Subject: [PATCH 8/8] Clients can talk to each other well:) --- client.js | 11 ++++++++--- server.js | 24 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/client.js b/client.js index e30a96e..355e037 100644 --- a/client.js +++ b/client.js @@ -5,12 +5,17 @@ var CONFIG = require('./config'); var socket = new net.Socket(); var client = socket.connect({ port: CONFIG.PORT }, function() { - console.log("CONNECTED TO: " + CONFIG.PORT); + + 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("SERVER BCAST FROM " + CONFIG.PORT + ": " + '"' + data + '"'); + client.write(clientAddress + ":" + clientPort + ': "' + data + '"'); }); + //socket.pipe(socket); + //client.end(); client.on('data', function(data) { console.log(data.toString()); @@ -18,6 +23,6 @@ var client = socket.connect({ port: CONFIG.PORT }, function() { client.on('end', function() { console.log("You have logged off:)"); - client.end(console.log("You have logged off:)")); + client.end("you have logged off:)"); }); }); diff --git a/server.js b/server.js index 90e14db..a47835f 100644 --- a/server.js +++ b/server.js @@ -2,24 +2,36 @@ var net = require('net'); var CONFIG = require('./config'); +var listOfClients = []; + //Connection listener var server = net.createServer(function (socket) { //Connection listener - console.log("CONNECTED: " + CONFIG.PORT); + var clientAddress = socket.remoteAddress.slice(7); + var clientPort = socket.remotePort; + listOfClients.push(socket); + + console.log("CONNECTED: " + clientAddress + ":" + clientPort); socket.on('end', function() { - console.log("\nCLOSED: " + CONFIG.PORT); + console.log("CLOSED: " + clientAddress + clientPort); }); - socket.pipe(socket); - process.stdin.on('data', function(data) { - socket.write("HOST: " + data); + socket.write("[ADMIN]" + ' "' + data + '"'); + // if(socket.write() === "kick") { + // socket.end(); + // } }); socket.on('data', function(data) { - console.log(data.toString()); + console.log("SERVER BCAST FROM " + data); + + listOfClients.forEach(function(client) { + client.write(data); + }); }); + //socket.pipe(socket); }); server.listen(CONFIG.PORT, function () {