From 256e9f1fb750173d6d7b1b6a6c9c7c0e4ad8976d Mon Sep 17 00:00:00 2001 From: keerthana Date: Mon, 25 Sep 2017 15:35:07 +0530 Subject: [PATCH 01/26] Json data to server --- Jsondata.js | 67 ++++++++++++++++++++++++++++++++++++++ Server.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 Jsondata.js create mode 100644 Server.js diff --git a/Jsondata.js b/Jsondata.js new file mode 100644 index 0000000..a09889b --- /dev/null +++ b/Jsondata.js @@ -0,0 +1,67 @@ +var http = require('http'); + +var data =JSON.stringify({ "Batch": [ { + "ProgramName":"p1" , + "UserName":"U1" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"7:77" , + "PayLoad":"hello" + } , + + { + "ProgramName":"p2" , + "UserName":"U2" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"2:22" , + "PayLoad":"hai" + }, + { + "ProgramName":"p3" , + "UserName":"U3" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"3:33" , + "PayLoad":"hello" + } , + + { + "ProgramName":"p2" , + "UserName":"U2" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"7:22" , + "PayLoad":"hai" + } + ] + } ) ; + + +var options = { + host: '10.200.208.44', + port: 8080, + path: '/eventslogs', + method: 'POST', + headers: + { + // 'Content-Type': 'application/jsondata', + 'Content-Type': 'text/plain', + 'Content-Length': Buffer.byteLength(data) + + } + }; + +var req = http.request(options, function(res) + { + res.setEncoding('utf8'); + res.on('data', function (chunk) { + console.log('got response from server ' + ' \n body: ' + chunk); + }); + +res.on('error', function (err){ + console.log(err); + }); + + }); +//writing json data on the specified end points +req.write(data); +//request ends +req.end(); + diff --git a/Server.js b/Server.js new file mode 100644 index 0000000..76075c8 --- /dev/null +++ b/Server.js @@ -0,0 +1,93 @@ +var express = require('express'); +var app = express(); +var bodyParser = require('body-parser'); +var http = require('http'); +var io = require('socket.io')(server); +var logs={}; +var logstream={}; +// creating a global variables +var pname, uname, ip, time, pload, logs; + +//parsing the text or string +app.use(bodyParser.text()); +app.use(express.static('public')); + +// Server listening to port 8080 +var server = http.createServer(app).listen(8080,function call() +{ + console.log('server address '+ server.address().address + ' listening to port '+ server.address().port ) ; +}); + + +// home page returns +app.get('/', function (req, res) +{ + res.send('HOME PAGE'); +}) + + + + +app.post('/eventslogs' , function (req, res) +{ + + +// parsing the data +// pname = logs.programName; uname = logs.UserName;ip = logs.IPaddress;time = logs.TimeStamp; pload = logs.PayLoad; + + +// parsing the request body +logs = JSON.parse(req.body); +console.log('the log stream data'+JSON.stringify(logs,null,2) ); + + +// access the each event object +var Eventobj = logs.Batch[0]; +console.log('log details'+ JSON.stringify(Eventobj,null,1) ); + + +// extracting the each property or key of an event object +console.log('pgm name'+ Eventobj.ProgramName); +console.log('*************************************') + + +for (var i = 0; i < logs.Batch.length; i++) { + var c = i+1; + var counter = logs.Batch[i]; + console.log('Event'+ c); + console.log("Program name:"+counter.ProgramName); + console.log("User name"+counter.UserName); + console.log("IP address"+counter.IPaddress); + console.log("Time stamp"+counter.TimeStamp); + console.log("Payload"+counter.PayLoad); + console.log('----------------------------------'); +} + +res.end(); +//logstream = logstream + logs; +//console.log('different logtream'+JSON.stringify(logstream,null,2) ); + +}) + + +// when a client request, the below function works.it routes to an api /logdetails +app.get('/logdetails', function (req, res) +{ + res.sendfile(__dirname + '/client.html'); +}); + +// io socket connection + +io.on('connection', function (socket) +{ + socket.on('initial',function(data) + { + console.log('response from client', data); + socket.emit('Eventlogs', logs); + } ) + + // have to emit when an update occurs + socket.emit('updates',logs); + +} ); + From c3b3a335f6fe9327320ff67816022098a9100d41 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:18:43 +0530 Subject: [PATCH 02/26] 'pseudocode' --- Jsondata.js | 106 ++++++++++++++++++++++++-------------------------- Pseudocode.md | 76 ++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 55 deletions(-) create mode 100644 Pseudocode.md diff --git a/Jsondata.js b/Jsondata.js index a09889b..0483283 100644 --- a/Jsondata.js +++ b/Jsondata.js @@ -1,65 +1,61 @@ var http = require('http'); -var data =JSON.stringify({ "Batch": [ { - "ProgramName":"p1" , - "UserName":"U1" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"7:77" , - "PayLoad":"hello" - } , - - { - "ProgramName":"p2" , - "UserName":"U2" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"2:22" , - "PayLoad":"hai" - }, - { - "ProgramName":"p3" , - "UserName":"U3" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"3:33" , - "PayLoad":"hello" - } , - - { - "ProgramName":"p2" , - "UserName":"U2" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"7:22" , - "PayLoad":"hai" - } - ] - } ) ; +var data =JSON.stringify({ + "Batch": [{ + "ProgramName":"p1" , + "UserName":"U1" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"7:77" , + "PayLoad":"hello" + }, + { + "ProgramName":"p2" , + "UserName":"U2" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"2:22" , + "PayLoad":"hai" + }, + { + "ProgramName":"p3" , + "UserName":"U3" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"3:33" , + "PayLoad":"hello" + }, + { + "ProgramName":"p2" , + "UserName":"U2" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"7:22" , + "PayLoad":"hai" + } + ] +}); var options = { - host: '10.200.208.44', - port: 8080, - path: '/eventslogs', - method: 'POST', - headers: - { - // 'Content-Type': 'application/jsondata', - 'Content-Type': 'text/plain', - 'Content-Length': Buffer.byteLength(data) - - } - }; + host: '10.200.208.44', + port: 8080, + path: '/eventslogs', + method: 'POST', + headers: { + // 'Content-Type': 'application/jsondata', + 'Content-Type': 'text/plain', + 'Content-Length': Buffer.byteLength(data) + } +}; -var req = http.request(options, function(res) - { - res.setEncoding('utf8'); - res.on('data', function (chunk) { - console.log('got response from server ' + ' \n body: ' + chunk); - }); - -res.on('error', function (err){ - console.log(err); - }); +var req = http.request(options, function(res) { + res.setEncoding('utf8'); + + res.on('data', function(chunk) { + console.log('got response from server ' + ' \n body: ' + chunk); + }); - }); + res.on('error', function(err) { + console.log(err); + }); +}); //writing json data on the specified end points req.write(data); //request ends diff --git a/Pseudocode.md b/Pseudocode.md new file mode 100644 index 0000000..52e3577 --- /dev/null +++ b/Pseudocode.md @@ -0,0 +1,76 @@ +# SERVER SIDE - Filter the data when it arrives +## Assume the below details are available at sever +### main object contains the entire event data till that time +### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. +### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} +GET Event_data; +Do + IF (Client not Present) + STORE Event_data in Main_Obj; + END IF + + ELSE + + FOR(EACH Obj in Client_Obj) + + FETCH filter variables(assume two values [P1(program_name),IP1(IP address)]); + STORE the filter variable values in local variables(pgmname,ipadd); + COMPARE pgmname with Event_data.programname; + + IF(TRUE) + + IF(COMPARE pgmname with Event_data.ipaddress) + SEND Event_data to Obj (it's Client id); + END IF + END IF + + END FOR + STORE Event_data in Main_Obj; + END ELSE +END DO + +#**************************************************************************************** + +#SERVER SIDE - Storing the Event_data in Main_obj +## Assume the below details are available at sever +### main object contains the entire event data till that time +### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids and CUID - Client UID +### LEI - Last Event Index , LEI = 0 , if client is created first. +### Client_UIDs = { CUID1 : [ P1, IP1, LEI1], CUID2 : [ P1, IP1, LEI2], CUID3 : [ P1, IP1, LEI3 ],..} +### programname_Object ={ p1 : [ EUID1, EUID2, EUID3] , p2 : [ EUID1, EUID2, EUID3] , p3 : [ EUID1, EUID2, EUID3] } and EUID - event UID +### EUID refers the Main_Obj +### Main_Obj structure - { EUID1:{ProgramName: p1, IPaddress : IP1, UserName :U1, TimeStamp : "7.77", Payload :"text" }, +### EUID2:{ProgramName: p3 IPaddress : IP2, UserName :U2, TimeStamp : "5.87", Payload :"happy" },..} + + +GET Event_data +DO + STORE it in Main_Obj; + + IF (Client Present) + + FOR(EACH obj in Client_Obj) + FETCH filter variables and LEI of that particular client (assume two values for filter and + last one - LEI { P1 (program_name), IP1 (IP address), LEI (Last Event Index) } ); + STORE the filter variable values in local variables( pgmname, ipadd, LEI); + 'lei' variable to store the last event index of that client. + CHECK the ' Key-Value Pair ' exist in programname_Object , according to the value of pgmname + THEN DO + FOR ( i = LEI ; i <= programname_Object.length) + FETCH EID and CHECK for IP address (another filter variable) is same + + IF(TRUE) + + SEND Event_data to that obj ( CUID in Client_Obj) + + END IF + + END FOR + lei = programname_Object.length; + WRITE the lei to that CUID.LEI--> lei + END DO + END FOR + END IF + + END DO + From 3f5ddb2032edabdad6ba9752aaeb67d59f00b67d Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:22:01 +0530 Subject: [PATCH 03/26] 'pseudocode' --- Pseudocode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pseudocode.md b/Pseudocode.md index 52e3577..d43d774 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -31,7 +31,7 @@ END DO #**************************************************************************************** -#SERVER SIDE - Storing the Event_data in Main_obj +# SERVER SIDE - Storing the Event_data in Main_obj ## Assume the below details are available at sever ### main object contains the entire event data till that time ### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids and CUID - Client UID From 80b7cf7a23672ec936181522c1e7d8c310a1cb37 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:35:00 +0530 Subject: [PATCH 04/26] 'pseudocode' --- Pseudocode.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index d43d774..ce26022 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,8 +1,13 @@ -# SERVER SIDE - Filter the data when it arrives +#****************************************************************************************************************** +# SERVER SIDE - Filter the data when it arrives +#****************************************************************************************************************** ## Assume the below details are available at sever ### main object contains the entire event data till that time ### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. ### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} + +#### Time complexity of the program is O(n) , if Client_Obj.length is n. + GET Event_data; Do IF (Client not Present) @@ -29,9 +34,14 @@ Do END ELSE END DO -#**************************************************************************************** -# SERVER SIDE - Storing the Event_data in Main_obj + +#......................................................................................................................... + +#************************************************************************************************************************** +# SERVER SIDE - Storing the Event_data in Main_obj +#************************************************************************************************************************** + ## Assume the below details are available at sever ### main object contains the entire event data till that time ### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids and CUID - Client UID @@ -42,6 +52,8 @@ END DO ### Main_Obj structure - { EUID1:{ProgramName: p1, IPaddress : IP1, UserName :U1, TimeStamp : "7.77", Payload :"text" }, ### EUID2:{ProgramName: p3 IPaddress : IP2, UserName :U2, TimeStamp : "5.87", Payload :"happy" },..} +#### Time complexity of the program is O(n*lei) , if Client_Obj.length is n and programname_Object.length is lei. + GET Event_data DO @@ -73,4 +85,4 @@ DO END IF END DO - +#............................................................................................................................. From 0404f10013b393aa4eed83be428fb348c891eaea Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:37:12 +0530 Subject: [PATCH 05/26] 'pseudocode' --- Pseudocode.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index ce26022..eb5e68b 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,6 +1,6 @@ -#****************************************************************************************************************** +# ****************************************************************************************************************** # SERVER SIDE - Filter the data when it arrives -#****************************************************************************************************************** +# ****************************************************************************************************************** ## Assume the below details are available at sever ### main object contains the entire event data till that time ### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. @@ -36,11 +36,11 @@ END DO -#......................................................................................................................... +# ........................................................................................................................................................................................................ -#************************************************************************************************************************** +# ************************************************************************************************************************** # SERVER SIDE - Storing the Event_data in Main_obj -#************************************************************************************************************************** +# ************************************************************************************************************************** ## Assume the below details are available at sever ### main object contains the entire event data till that time @@ -85,4 +85,4 @@ DO END IF END DO -#............................................................................................................................. +# ...................................................................................................................................................................................................... \ No newline at end of file From 6ecda593b49101f1a2ce91cb02db7b56c9198f65 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:39:59 +0530 Subject: [PATCH 06/26] 'pseudocode' --- Pseudocode.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index eb5e68b..e3501c0 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,6 +1,6 @@ -# ****************************************************************************************************************** -# SERVER SIDE - Filter the data when it arrives -# ****************************************************************************************************************** +# ************************************************* +# SERVER SIDE - Filter the data when it arrives +# ************************************************* ## Assume the below details are available at sever ### main object contains the entire event data till that time ### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. @@ -36,11 +36,11 @@ END DO -# ........................................................................................................................................................................................................ +# ...................................................... -# ************************************************************************************************************************** -# SERVER SIDE - Storing the Event_data in Main_obj -# ************************************************************************************************************************** +# ****************************************************** +# SERVER SIDE - Storing the Event_data in Main_obj +# ****************************************************** ## Assume the below details are available at sever ### main object contains the entire event data till that time @@ -85,4 +85,4 @@ DO END IF END DO -# ...................................................................................................................................................................................................... \ No newline at end of file +# .......................................................... \ No newline at end of file From c0d8a15d8b5a3fd1a0384a2761aaae8585161484 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:44:46 +0530 Subject: [PATCH 07/26] 'pseudocode' --- Pseudocode.md | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index e3501c0..fa2407d 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,17 +1,19 @@ -# ************************************************* +### ************************************************* # SERVER SIDE - Filter the data when it arrives -# ************************************************* +### ************************************************* ## Assume the below details are available at sever -### main object contains the entire event data till that time -### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. -### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} +#### main object contains the entire event data till the current time +#### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. +#### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} #### Time complexity of the program is O(n) , if Client_Obj.length is n. GET Event_data; -Do +DO IF (Client not Present) + STORE Event_data in Main_Obj; + END IF ELSE @@ -36,21 +38,21 @@ END DO -# ...................................................... +### ...................................................... -# ****************************************************** +### ****************************************************** # SERVER SIDE - Storing the Event_data in Main_obj -# ****************************************************** +### ****************************************************** ## Assume the below details are available at sever -### main object contains the entire event data till that time -### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids and CUID - Client UID -### LEI - Last Event Index , LEI = 0 , if client is created first. -### Client_UIDs = { CUID1 : [ P1, IP1, LEI1], CUID2 : [ P1, IP1, LEI2], CUID3 : [ P1, IP1, LEI3 ],..} -### programname_Object ={ p1 : [ EUID1, EUID2, EUID3] , p2 : [ EUID1, EUID2, EUID3] , p3 : [ EUID1, EUID2, EUID3] } and EUID - event UID -### EUID refers the Main_Obj -### Main_Obj structure - { EUID1:{ProgramName: p1, IPaddress : IP1, UserName :U1, TimeStamp : "7.77", Payload :"text" }, -### EUID2:{ProgramName: p3 IPaddress : IP2, UserName :U2, TimeStamp : "5.87", Payload :"happy" },..} +#### main object contains the entire event data till the current time +#### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids and CUID - Client UID +#### LEI - Last Event Index , LEI = 0 , if client is created first. +#### Client_UIDs = { CUID1 : [ P1, IP1, LEI1], CUID2 : [ P1, IP1, LEI2], CUID3 : [ P1, IP1, LEI3 ],..} +#### programname_Object ={ p1 : [ EUID1, EUID2, EUID3] , p2 : [ EUID1, EUID2, EUID3] , p3 : [ EUID1, EUID2, EUID3] } and EUID - event UID +#### EUID refers the Main_Obj +#### Main_Obj structure - { EUID1:{ProgramName: p1, IPaddress : IP1, UserName :U1, TimeStamp : "7.77", Payload :"text" }, +#### EUID2:{ProgramName: p3 IPaddress : IP2, UserName :U2, TimeStamp : "5.87", Payload :"happy" },..} #### Time complexity of the program is O(n*lei) , if Client_Obj.length is n and programname_Object.length is lei. @@ -85,4 +87,4 @@ DO END IF END DO -# .......................................................... \ No newline at end of file +### .......................................................... \ No newline at end of file From b2204316bff6b36a9ee5f203ddaad2220dcc6e66 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:46:34 +0530 Subject: [PATCH 08/26] 'pseudocode' --- Pseudocode.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index fa2407d..bac0b3c 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,6 +1,6 @@ -### ************************************************* +## ************************************************* # SERVER SIDE - Filter the data when it arrives -### ************************************************* +## ************************************************* ## Assume the below details are available at sever #### main object contains the entire event data till the current time #### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. @@ -38,11 +38,11 @@ END DO -### ...................................................... +## ...................................................... -### ****************************************************** +## ****************************************************** # SERVER SIDE - Storing the Event_data in Main_obj -### ****************************************************** +## ****************************************************** ## Assume the below details are available at sever #### main object contains the entire event data till the current time From 265eaba375274382b791b4867a34a0e6512d3779 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 18 Oct 2017 15:47:48 +0530 Subject: [PATCH 09/26] 'pseudocode' --- Pseudocode.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index bac0b3c..8a50140 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,6 +1,6 @@ -## ************************************************* +# ************************************************* # SERVER SIDE - Filter the data when it arrives -## ************************************************* +# ************************************************* ## Assume the below details are available at sever #### main object contains the entire event data till the current time #### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. @@ -38,11 +38,11 @@ END DO -## ...................................................... +# ...................................................... -## ****************************************************** +# ****************************************************** # SERVER SIDE - Storing the Event_data in Main_obj -## ****************************************************** +# ****************************************************** ## Assume the below details are available at sever #### main object contains the entire event data till the current time @@ -87,4 +87,4 @@ DO END IF END DO -### .......................................................... \ No newline at end of file +# .......................................................... \ No newline at end of file From 95d675e7ac57946d63f1d756789e2897e2e07fee Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 25 Oct 2017 16:26:06 +0530 Subject: [PATCH 10/26] for general filter variables --- Pseudocode1.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Pseudocode1.md diff --git a/Pseudocode1.md b/Pseudocode1.md new file mode 100644 index 0000000..2b92952 --- /dev/null +++ b/Pseudocode1.md @@ -0,0 +1,51 @@ +# ************************************************* +# SERVER SIDE - Filter the data when it arrives +# ************************************************* +## Assume the below details are available at server +#### main object contains the entire event data till the current time +#### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. +#### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} + +#### Time complexity of the program is O(n) , if Client_Obj.length is n. + +GET Event_data; +DO + IF (Client not Present) + + STORE Event_data in Main_Obj; + + END IF + + ELSE + + FOR (EACH Obj in Client_Obj) + + FETCH Filter_Variables(Values may be [P1(program_name),IP1(IP address),etc]); + + FOR ( i=0; i< (Filter_Variables.Length - 1 ) ; i++) + + COMPARE Filter_Variables[i] with Event_data.KeyValue; + + IF (Comparison is TRUE) + CONTINUE; + END IF + + ELSE + SET FLAG TO 0 + BREAK; + END ELSE + + END FOR + + IF(FLAG) + SEND Event_data to Obj (it's Client id); + END IF + + END FOR + STORE Event_data in Main_Obj; + + END ELSE + +END DO + + From 6920cf11be4443795a0ca276e2564e4249c769b1 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 25 Oct 2017 21:34:35 +0530 Subject: [PATCH 11/26] filtering with any number of variables --- Pseudocode.md | 4 +-- Pseudocode1.md | 77 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/Pseudocode.md b/Pseudocode.md index 8a50140..5f35682 100644 --- a/Pseudocode.md +++ b/Pseudocode.md @@ -1,7 +1,7 @@ # ************************************************* # SERVER SIDE - Filter the data when it arrives # ************************************************* -## Assume the below details are available at sever +## Assume the below details are available at server #### main object contains the entire event data till the current time #### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. #### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} @@ -41,7 +41,7 @@ END DO # ...................................................... # ****************************************************** -# SERVER SIDE - Storing the Event_data in Main_obj +# SERVER SIDE - Storing the Event_data in Main_obj and then filtering the data # ****************************************************** ## Assume the below details are available at sever diff --git a/Pseudocode1.md b/Pseudocode1.md index 2b92952..7f86fa9 100644 --- a/Pseudocode1.md +++ b/Pseudocode1.md @@ -4,7 +4,9 @@ ## Assume the below details are available at server #### main object contains the entire event data till the current time #### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. -#### Client_UIDs = { CUID1 : [P1,IP1], CUID2 : [P1,IP1], CUID3 : [P1,IP1],..} +#### Client_UIDs = { CUID1 : { PropertyName:P1, IPaddress:IP1}, +#### CUID2 : [ PropertyName:P1, IPaddress:IP1], +#### CUID3 : [PropertyName:P1, IPaddress:IP1],..} #### Time complexity of the program is O(n) , if Client_Obj.length is n. @@ -18,32 +20,53 @@ DO ELSE - FOR (EACH Obj in Client_Obj) - - FETCH Filter_Variables(Values may be [P1(program_name),IP1(IP address),etc]); - - FOR ( i=0; i< (Filter_Variables.Length - 1 ) ; i++) - - COMPARE Filter_Variables[i] with Event_data.KeyValue; - - IF (Comparison is TRUE) - CONTINUE; - END IF - - ELSE - SET FLAG TO 0 - BREAK; - END ELSE - - END FOR - - IF(FLAG) - SEND Event_data to Obj (it's Client id); - END IF - - END FOR - STORE Event_data in Main_Obj; - + FOR EACH Obj in Client_Obj + + FOR EACH key in Obj + + IF obj.hasOwnProperty(key) + + key == Program_Name + + IF ( COMPARE obj.key with Event_data.Program_Name ) + + END IF + ELSE + SET FLAG = 0; + BREAK;// coming out of the property checking since it failed in comparison + + key == IPaddress + + IF ( COMPARE obj.key with Event_data.IPaddress) + + END IF + ELSE + SET FLAG = 0; + BREAK; + key == UserName + IF ( COMPARE obj.key with Event_data.UserName ) + + END IF + ELSE + SET FLAG = 0; + BREAK; + + END IF + END FOR + + // we can have the above module for any number of variables. + + + IF (FLAG) + SEND Event_data to Obj (it's Client id); + END + END FOR + + STORE Event_data in Main_Obj; + + + + END ELSE END DO From f3a87f6a1b73a4365af00e3ebcc3af1e7b78ff05 Mon Sep 17 00:00:00 2001 From: keerthana Date: Thu, 26 Oct 2017 12:40:21 +0530 Subject: [PATCH 12/26] 'Pseudocode' --- Pseudocode1.md | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/Pseudocode1.md b/Pseudocode1.md index 7f86fa9..1ef2121 100644 --- a/Pseudocode1.md +++ b/Pseudocode1.md @@ -4,9 +4,9 @@ ## Assume the below details are available at server #### main object contains the entire event data till the current time #### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. -#### Client_UIDs = { CUID1 : { PropertyName:P1, IPaddress:IP1}, -#### CUID2 : [ PropertyName:P1, IPaddress:IP1], -#### CUID3 : [PropertyName:P1, IPaddress:IP1],..} +#### Client_UIDs = { CUID1 : { PropertyName:P1, IPaddress:IP1,etc}, +#### CUID2 : [IPaddress:IP1,PropertyName:P1,etc], +#### CUID3 : [UserName: U1, IPaddress:IP1],..} #### Time complexity of the program is O(n) , if Client_Obj.length is n. @@ -29,44 +29,40 @@ DO key == Program_Name IF ( COMPARE obj.key with Event_data.Program_Name ) - + CONTINUE; END IF ELSE - SET FLAG = 0; - BREAK;// coming out of the property checking since it failed in comparison + SET FLAG = 0; + BREAK;// coming out of the property checking since it failed in comparison key == IPaddress IF ( COMPARE obj.key with Event_data.IPaddress) - + CONTINUE; END IF ELSE - SET FLAG = 0; - BREAK; + SET FLAG = 0; + BREAK; key == UserName + IF ( COMPARE obj.key with Event_data.UserName ) - + CONTINUE; END IF ELSE - SET FLAG = 0; - BREAK; - - END IF - END FOR - - // we can have the above module for any number of variables. + SET FLAG = 0; + BREAK; + END IF + END FOR - IF (FLAG) SEND Event_data to Obj (it's Client id); - END + END + END FOR - STORE Event_data in Main_Obj; + STORE Event_data in Main_Obj; - - END ELSE END DO From 1d88d0a021cdef2babc20500d69f5ed7423d6d61 Mon Sep 17 00:00:00 2001 From: keerthana Date: Thu, 26 Oct 2017 16:30:35 +0530 Subject: [PATCH 13/26] 'pseudocodev2' --- pseudocode v2.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pseudocode v2.md diff --git a/pseudocode v2.md b/pseudocode v2.md new file mode 100644 index 0000000..e5b1a11 --- /dev/null +++ b/pseudocode v2.md @@ -0,0 +1,51 @@ +# ************************************************* +# SERVER SIDE - Filter the data when it arrives +# ************************************************* +## Assume the below details are available at server +#### main object contains the entire event data till the current time +#### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. +#### Client_UIDs = { CUID1 : { PropertyName:P1, IPaddress:IP1,etc}, +#### CUID2 : [IPaddress:IP1,PropertyName:P1,etc], +#### CUID3 : [UserName: U1, IPaddress:IP1],..} + +#### Time complexity of the program is O(n) , if Client_Obj.length is n. + +GET Event_data; +DO + IF (Client not Present) + + STORE Event_data in Main_Obj; + + END IF + + ELSE + + FOR EACH Obj in Client_Obj + + FOR EACH key in Obj + + + IF ( CHECK key in Event_data ) + COMPARE obj.key with Event_data.key + CONTINUE; + END IF + ELSE + SET FLAG = 0; + BREAK; // coming out of the property checking since it failed in comparison + + END ELSE + END FOR + + IF (FLAG) + SEND Event_data to Obj (it's Client id); + END + + END FOR + + STORE Event_data in Main_Obj; + + END ELSE + +END DO + + From 4a346f787b8c2e4b8b9613febfaa3f2d44dbc0f9 Mon Sep 17 00:00:00 2001 From: keerthana Date: Thu, 26 Oct 2017 16:39:27 +0530 Subject: [PATCH 14/26] 'Pseudocodev2' --- Pseudocode1.md | 43 ++++++++++++---------------------------- pseudocode v2.md | 51 ------------------------------------------------ 2 files changed, 12 insertions(+), 82 deletions(-) delete mode 100644 pseudocode v2.md diff --git a/Pseudocode1.md b/Pseudocode1.md index 1ef2121..e5b1a11 100644 --- a/Pseudocode1.md +++ b/Pseudocode1.md @@ -24,45 +24,26 @@ DO FOR EACH key in Obj - IF obj.hasOwnProperty(key) - - key == Program_Name - - IF ( COMPARE obj.key with Event_data.Program_Name ) - CONTINUE; - END IF - ELSE - SET FLAG = 0; - BREAK;// coming out of the property checking since it failed in comparison - - key == IPaddress - - IF ( COMPARE obj.key with Event_data.IPaddress) - CONTINUE; - END IF - ELSE - SET FLAG = 0; - BREAK; - key == UserName - - IF ( COMPARE obj.key with Event_data.UserName ) - CONTINUE; - END IF - ELSE - SET FLAG = 0; - BREAK; + + IF ( CHECK key in Event_data ) + COMPARE obj.key with Event_data.key + CONTINUE; END IF + ELSE + SET FLAG = 0; + BREAK; // coming out of the property checking since it failed in comparison + + END ELSE END FOR - IF (FLAG) - SEND Event_data to Obj (it's Client id); - END + IF (FLAG) + SEND Event_data to Obj (it's Client id); + END END FOR STORE Event_data in Main_Obj; - END ELSE END DO diff --git a/pseudocode v2.md b/pseudocode v2.md deleted file mode 100644 index e5b1a11..0000000 --- a/pseudocode v2.md +++ /dev/null @@ -1,51 +0,0 @@ -# ************************************************* -# SERVER SIDE - Filter the data when it arrives -# ************************************************* -## Assume the below details are available at server -#### main object contains the entire event data till the current time -#### Client_Obj = [CUID1,CUID2,CUID3,..] - Client_Obj is an array to store the client ids. -#### Client_UIDs = { CUID1 : { PropertyName:P1, IPaddress:IP1,etc}, -#### CUID2 : [IPaddress:IP1,PropertyName:P1,etc], -#### CUID3 : [UserName: U1, IPaddress:IP1],..} - -#### Time complexity of the program is O(n) , if Client_Obj.length is n. - -GET Event_data; -DO - IF (Client not Present) - - STORE Event_data in Main_Obj; - - END IF - - ELSE - - FOR EACH Obj in Client_Obj - - FOR EACH key in Obj - - - IF ( CHECK key in Event_data ) - COMPARE obj.key with Event_data.key - CONTINUE; - END IF - ELSE - SET FLAG = 0; - BREAK; // coming out of the property checking since it failed in comparison - - END ELSE - END FOR - - IF (FLAG) - SEND Event_data to Obj (it's Client id); - END - - END FOR - - STORE Event_data in Main_Obj; - - END ELSE - -END DO - - From f003a66446f053ab90d3a208221916a0bb37d9b8 Mon Sep 17 00:00:00 2001 From: keerthana Date: Tue, 31 Oct 2017 18:06:54 +0530 Subject: [PATCH 15/26] 'first_version' --- Jsondata.js | 80 +++++++++-------------- Server.js | 183 +++++++++++++++++++++++++++++++++------------------- client.html | 45 +++++++++++++ 3 files changed, 192 insertions(+), 116 deletions(-) create mode 100644 client.html diff --git a/Jsondata.js b/Jsondata.js index 0483283..cbc41e1 100644 --- a/Jsondata.js +++ b/Jsondata.js @@ -1,61 +1,39 @@ var http = require('http'); -var data =JSON.stringify({ - "Batch": [{ - "ProgramName":"p1" , - "UserName":"U1" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"7:77" , - "PayLoad":"hello" - }, - { - "ProgramName":"p2" , - "UserName":"U2" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"2:22" , - "PayLoad":"hai" - }, - { - "ProgramName":"p3" , - "UserName":"U3" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"3:33" , - "PayLoad":"hello" - }, - { - "ProgramName":"p2" , - "UserName":"U2" , - "IPaddress":" 10.200.208.44" , - "TimeStamp":"7:22" , - "PayLoad":"hai" - } - ] -}); +var data = JSON.stringify( { "ProgramName":"p1" , + "UserName":"U1" , + "IPaddress":" 10.200.208.44" , + "TimeStamp":"7:77" , +"PayLoad":"hello" } + ) ; var options = { - host: '10.200.208.44', - port: 8080, - path: '/eventslogs', - method: 'POST', - headers: { - // 'Content-Type': 'application/jsondata', - 'Content-Type': 'text/plain', - 'Content-Length': Buffer.byteLength(data) - } -}; - -var req = http.request(options, function(res) { - res.setEncoding('utf8'); + host: '10.200.208.44', + port: 8080, + path: '/eventslogs', + method: 'POST', + headers: + { + // 'Content-Type': 'application/jsondata', + 'Content-Type': 'text/plain', + 'Content-Length': Buffer.byteLength(data) - res.on('data', function(chunk) { - console.log('got response from server ' + ' \n body: ' + chunk); - }); + } + }; + +var req = http.request(options, function(res) + { + res.setEncoding('utf8'); + res.on('data', function (chunk) { + console.log('got response from server ' + ' \n body: ' + chunk); + }); + +res.on('error', function (err){ + console.log(err); + }); - res.on('error', function(err) { - console.log(err); - }); -}); + }); //writing json data on the specified end points req.write(data); //request ends diff --git a/Server.js b/Server.js index 76075c8..14ce431 100644 --- a/Server.js +++ b/Server.js @@ -1,93 +1,146 @@ -var express = require('express'); -var app = express(); -var bodyParser = require('body-parser'); -var http = require('http'); -var io = require('socket.io')(server); -var logs={}; -var logstream={}; -// creating a global variables -var pname, uname, ip, time, pload, logs; +var express = require('express'), + app = express(), + bodyParser = require('body-parser'), + http = require('http'), + uid = require('uid'), + data={}, + count =0, + eid, + keyfields, + logs={}, + logstream={}, + cid, + connectedclients={}; + +eid=uid(); //parsing the text or string app.use(bodyParser.text()); -app.use(express.static('public')); -// Server listening to port 8080 -var server = http.createServer(app).listen(8080,function call() + + +var server = http.createServer(app).listen('8080','10.200.208.44'); + +server.on('listening', function () { - console.log('server address '+ server.address().address + ' listening to port '+ server.address().port ) ; -}); +console.log('server listening'); +}); +var io = require('socket.io').listen(server); // home page returns -app.get('/', function (req, res) +app.use(express.static(__dirname +'/node_modules/socket.io-client/dist')); +app.get('/', function (req, res) { res.send('HOME PAGE'); -}) - - - + +}); -app.post('/eventslogs' , function (req, res) +app.get('/socket.io/socket.io.js', function (req, res) { + res.sendFile(__dirname + '/node_modules/socket.io-client/lib/socket.io.js'); + +}); +// when a client request, the below function works.it routes to an api /logdetails -// parsing the data -// pname = logs.programName; uname = logs.UserName;ip = logs.IPaddress;time = logs.TimeStamp; pload = logs.PayLoad; - - -// parsing the request body -logs = JSON.parse(req.body); -console.log('the log stream data'+JSON.stringify(logs,null,2) ); - - -// access the each event object -var Eventobj = logs.Batch[0]; -console.log('log details'+ JSON.stringify(Eventobj,null,1) ); - +app.get('/logdetails', function (req, res) +{ + res.sendFile(__dirname + '/client1.html'); +}); -// extracting the each property or key of an event object -console.log('pgm name'+ Eventobj.ProgramName); -console.log('*************************************') +// create client ids +function createclientsids(d) +{ + connectedclients[d] = ' '; + + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); -for (var i = 0; i < logs.Batch.length; i++) { - var c = i+1; - var counter = logs.Batch[i]; - console.log('Event'+ c); - console.log("Program name:"+counter.ProgramName); - console.log("User name"+counter.UserName); - console.log("IP address"+counter.IPaddress); - console.log("Time stamp"+counter.TimeStamp); - console.log("Payload"+counter.PayLoad); - console.log('----------------------------------'); } +// delete clients +function deleteclients(dd) +{ + delete connectedclients[dd]; + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); +} +// socket io cnnection +io.on('connection', function (socket) +{ -res.end(); -//logstream = logstream + logs; -//console.log('different logtream'+JSON.stringify(logstream,null,2) ); -}) + count += 1; + console.log('.............................'); + console.log('A user is connected'); + console.log(count + ' '+ 'client connected with id ' +' '+ socket.id); + cid = socket.id; + createclientsids(cid); + socket.on('initial',function(res) + { + console.log('response from client', res); + socket.emit('Eventlogs', data); + + } ) + +// have to emit when an update occurs + // socket.emit('updates',logs); + socket.on('disconnect',function() + { + count-=1; + console.log('.............................'); + console.log('client disconnected with id' +' '+ socket.id); + deleteclients(socket.id); + + }); + + -// when a client request, the below function works.it routes to an api /logdetails -app.get('/logdetails', function (req, res) -{ - res.sendfile(__dirname + '/client.html'); }); +//console.log('total connected clients'+ connectedclients); +// appending the data +function store(eid,logs) +{ + data[eid]= data + logs; + for(var key in data) + { + console.log('data.uid'+ key + JSON.stringify(data[key])); + } -// io socket connection +} -io.on('connection', function (socket) + +app.post('/eventslogs' , function (req, res) { - socket.on('initial',function(data) - { - console.log('response from client', data); - socket.emit('Eventlogs', logs); - } ) - - // have to emit when an update occurs - socket.emit('updates',logs); -} ); + // parsing the request body + keyfields = JSON.parse(req.body); + console.log("req.body"+ JSON.stringify(keyfields,1,1)); + for(var key in keyfields) + { + logs[key] = keyfields[key]; + console.log('key + logs.key'+ key + logs[key]); + } + eid = uid(); + if (connectedclients && connectedclients =="undefined" || connectedclients == 'null') + { + + console.log('clients are not connected'); + console.log('eid'+ eid) + store(eid,logs); + } + + else + { + + /* filtering checking code comes here */ + console.log('clients are connected'); + store(eid,logs); + + } + + res.end(); +}) diff --git a/client.html b/client.html new file mode 100644 index 0000000..447308b --- /dev/null +++ b/client.html @@ -0,0 +1,45 @@ + + + + socket.io + + + + +
+
+ +

communication with socket.io

+ + + + + + + + + \ No newline at end of file From 9be3ff4360f065430c78b5319bda4a4a15bf8ebd Mon Sep 17 00:00:00 2001 From: keerthana Date: Tue, 31 Oct 2017 20:42:11 +0530 Subject: [PATCH 16/26] 'first_version' --- Server.js | 138 ++++++++++++++++++++++++------------------------------ 1 file changed, 61 insertions(+), 77 deletions(-) diff --git a/Server.js b/Server.js index 14ce431..1ef5c8d 100644 --- a/Server.js +++ b/Server.js @@ -3,33 +3,28 @@ var express = require('express'), bodyParser = require('body-parser'), http = require('http'), uid = require('uid'), - data={}, - count =0, + data = {}, + logs = {}, + logstream = {}, + connectedclients = {}, + count = 0, eid, keyfields, - logs={}, - logstream={}, - cid, - connectedclients={}; - -eid=uid(); + cid; + + // eid=uid(); +var server = http.createServer(app).listen('8080','10.200.208.44'); +var io = require('socket.io').listen(server); //parsing the text or string app.use(bodyParser.text()); - - -var server = http.createServer(app).listen('8080','10.200.208.44'); - server.on('listening', function () { -console.log('server listening'); + console.log('server listening'); }); -var io = require('socket.io').listen(server); -// home page returns -app.use(express.static(__dirname +'/node_modules/socket.io-client/dist')); app.get('/', function (req, res) { res.send('HOME PAGE'); @@ -38,7 +33,7 @@ app.get('/', function (req, res) app.get('/socket.io/socket.io.js', function (req, res) { - res.sendFile(__dirname + '/node_modules/socket.io-client/lib/socket.io.js'); + res.sendFile(__dirname + '/node_modules/socket.io-client/lib/socket.io.js'); }); @@ -49,28 +44,9 @@ app.get('/logdetails', function (req, res) res.sendFile(__dirname + '/client1.html'); }); -// create client ids -function createclientsids(d) -{ - connectedclients[d] = ' '; - - console.log('total clientsconnected'+' '+ count); - console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); - -} -// delete clients -function deleteclients(dd) -{ - delete connectedclients[dd]; - console.log('total clientsconnected'+' '+ count); - console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); -} -// socket io cnnection io.on('connection', function (socket) { - - count += 1; console.log('.............................'); console.log('A user is connected'); @@ -80,37 +56,21 @@ io.on('connection', function (socket) socket.on('initial',function(res) { - console.log('response from client', res); - socket.emit('Eventlogs', data); - - } ) - -// have to emit when an update occurs - // socket.emit('updates',logs); - socket.on('disconnect',function() - { - count-=1; - console.log('.............................'); - console.log('client disconnected with id' +' '+ socket.id); - deleteclients(socket.id); - - }); + console.log('response from client', res); + socket.emit('Eventlogs', data); - + }); -}); -//console.log('total connected clients'+ connectedclients); -// appending the data -function store(eid,logs) -{ - data[eid]= data + logs; - for(var key in data) + socket.on('disconnect',function() { - console.log('data.uid'+ key + JSON.stringify(data[key])); - } + count-=1; + console.log('.............................'); + console.log('client disconnected with id' +' '+ socket.id); + deleteclients(socket.id); -} + }); +}); app.post('/eventslogs' , function (req, res) { @@ -120,27 +80,51 @@ app.post('/eventslogs' , function (req, res) console.log("req.body"+ JSON.stringify(keyfields,1,1)); for(var key in keyfields) { - logs[key] = keyfields[key]; - console.log('key + logs.key'+ key + logs[key]); + logs[key] = keyfields[key]; + console.log('key + logs.key'+ key + logs[key]); } + eid = uid(); - if (connectedclients && connectedclients =="undefined" || connectedclients == 'null') + //if (connectedclients && connectedclients =="undefined" || connectedclients == 'null') + if (Object.keys(connectedclients).length) { - - console.log('clients are not connected'); - console.log('eid'+ eid) - store(eid,logs); - + /* filtering checking code comes here */ + console.log('clients are connected'); + store(eid,logs); } - + else { + console.log('clients are not connected'); + console.log('eid'+ eid) + store(eid,logs); + } - /* filtering checking code comes here */ - console.log('clients are connected'); - store(eid,logs); + res.end(); +}); + +//creating clients ids +function createclientsids(d) +{ + connectedclients[d] = ' '; + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); +} +// deleting disconnected clients +function deleteclients(dd) +{ + delete connectedclients[dd]; + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); +} +//storing the data +function store(eid,logs) +{ + data[eid]= data + logs; + for(var key in data) + { + console.log('data.uid'+ key + JSON.stringify(data[key])); } - - res.end(); -}) + +} \ No newline at end of file From a31663c84c2c6c47d716263d372bb5f0fc7e6bb2 Mon Sep 17 00:00:00 2001 From: keerthana Date: Thu, 2 Nov 2017 14:04:01 +0530 Subject: [PATCH 17/26] 'version-1' --- Server.js | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/Server.js b/Server.js index 1ef5c8d..622dcb6 100644 --- a/Server.js +++ b/Server.js @@ -4,15 +4,13 @@ var express = require('express'), http = require('http'), uid = require('uid'), data = {}, - logs = {}, logstream = {}, connectedclients = {}, + objectvalue = {}, count = 0, eid, keyfields, cid; - - // eid=uid(); var server = http.createServer(app).listen('8080','10.200.208.44'); var io = require('socket.io').listen(server); @@ -74,6 +72,7 @@ io.on('connection', function (socket) app.post('/eventslogs' , function (req, res) { + var logs = {}; // parsing the request body keyfields = JSON.parse(req.body); @@ -99,7 +98,7 @@ app.post('/eventslogs' , function (req, res) console.log('eid'+ eid) store(eid,logs); } - +console.log('the log data'+ JSON.stringify(logs,null,2)); res.end(); }); @@ -115,16 +114,55 @@ function deleteclients(dd) { delete connectedclients[dd]; console.log('total clientsconnected'+' '+ count); - console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); + console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); } //storing the data function store(eid,logs) { - data[eid]= data + logs; + //for showing data data[eid]= data + JSON.stringify(logs); +//data[eid]= data + JSON.stringify(logs); +data[eid]= logs; + + for(var key in data) { - console.log('data.uid'+ key + JSON.stringify(data[key])); + console.log('data with data id' + ' '+key +' '+JSON.stringify(data[key],null,2) ); + + var temp = data[key]; + + if(!Object.keys(objectvalue).length) + { + + for(k in temp) + { + console.log('enter into the if case to create a new one') + objectvalue[temp[k]] = []; + objectvalue[temp[k]].push(key); + + //console.log('temp data with k and value'+ k +' '+objectvalue[temp[k]]); + } + + } + else + { + for(k in temp) + { + if(objectvalue.hasOwnProperty(temp.k)) + { + console.log('enter into the has own property') + objectvalue[temp[k]].push(key); + } + else + { + console.log('enter into else part of has own property') + objectvalue[temp[k]] = []; + objectvalue[temp[k]].push(key); + } + } + } } + console.log('object value'+JSON.stringify(objectvalue,null,2)); + } \ No newline at end of file From 03a9cce2f980ec22eb0dfe9952e0bab1c4a8c643 Mon Sep 17 00:00:00 2001 From: keerthana Date: Thu, 2 Nov 2017 15:11:59 +0530 Subject: [PATCH 18/26] 'version-1' --- Server.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Server.js b/Server.js index 622dcb6..1c31962 100644 --- a/Server.js +++ b/Server.js @@ -125,22 +125,20 @@ function store(eid,logs) data[eid]= logs; - for(var key in data) - { - console.log('data with data id' + ' '+key +' '+JSON.stringify(data[key],null,2) ); + + console.log('data with data id' + ' '+ eid +' '+JSON.stringify(data[eid],null,2) ); - var temp = data[key]; + var temp = logs; if(!Object.keys(objectvalue).length) { for(k in temp) { - console.log('enter into the if case to create a new one') + console.log('enter into the if case to create a new one'); objectvalue[temp[k]] = []; - objectvalue[temp[k]].push(key); + objectvalue[temp[k]].push(eid); - //console.log('temp data with k and value'+ k +' '+objectvalue[temp[k]]); } } @@ -148,20 +146,21 @@ data[eid]= logs; { for(k in temp) { - if(objectvalue.hasOwnProperty(temp.k)) + if(objectvalue.hasOwnProperty(temp[k])) { - console.log('enter into the has own property') - objectvalue[temp[k]].push(key); + console.log('enter into the has own property'); + + objectvalue[temp[k]].push(eid); } else { - console.log('enter into else part of has own property') + console.log('enter into else part of has own property'); objectvalue[temp[k]] = []; - objectvalue[temp[k]].push(key); + objectvalue[temp[k]].push(eid); } } } - } + console.log('object value'+JSON.stringify(objectvalue,null,2)); From 6caa6534bd7b99470cada2faea8d7c21a0e5d6db Mon Sep 17 00:00:00 2001 From: keerthana Date: Fri, 3 Nov 2017 11:33:03 +0530 Subject: [PATCH 19/26] 'version-1.1' --- Server.js | 60 ++++++++++++++++++++++++++++++++++++----------------- client.html | 14 ++++++------- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/Server.js b/Server.js index 1c31962..518d534 100644 --- a/Server.js +++ b/Server.js @@ -7,11 +7,13 @@ var express = require('express'), logstream = {}, connectedclients = {}, objectvalue = {}, + filtervar = [], + Eventids = [], count = 0, eid, keyfields, cid; - +var fdata={}; var server = http.createServer(app).listen('8080','10.200.208.44'); var io = require('socket.io').listen(server); //parsing the text or string @@ -50,14 +52,36 @@ io.on('connection', function (socket) console.log('A user is connected'); console.log(count + ' '+ 'client connected with id ' +' '+ socket.id); cid = socket.id; - createclientsids(cid); + //createclientsids(cid); + + connectedclients[cid] = 'p3'; + Eventids = objectvalue[connectedclients[cid]]; + console.log('the event ids length'+ Eventids.length+ ' '+ 'they are'+Eventids); - socket.on('initial',function(res) - { - console.log('response from client', res); - socket.emit('Eventlogs', data); + if(Eventids.length) + { + for(var i = 0;i < Eventids.length; i++) + { + if(data.hasOwnProperty(Eventids[i])) + { + console.log('filtered data id to the client'+' '+Eventids[i]+' '+JSON.stringify(data[Eventids[i]],null,2)); + socket.emit('filtered data',JSON.stringify(data[Eventids[i]],null,2)); + } - }); + } + + } + + + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); + + // socket.on('initial',function(res) + // { + // console.log('response from client', res); + // socket.emit('Eventlogs', data); + + // }); socket.on('disconnect',function() { @@ -69,6 +93,7 @@ io.on('connection', function (socket) }); }); + app.post('/eventslogs' , function (req, res) { @@ -84,7 +109,7 @@ app.post('/eventslogs' , function (req, res) } eid = uid(); - //if (connectedclients && connectedclients =="undefined" || connectedclients == 'null') + if (Object.keys(connectedclients).length) { /* filtering checking code comes here */ @@ -103,12 +128,12 @@ console.log('the log data'+ JSON.stringify(logs,null,2)); }); //creating clients ids -function createclientsids(d) -{ - connectedclients[d] = ' '; - console.log('total clientsconnected'+' '+ count); - console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); -} +// function createclientsids(d) +// { +// connectedclients[d] = 'p1'; +// console.log('total clientsconnected'+' '+ count); +// console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); +// } // deleting disconnected clients function deleteclients(dd) { @@ -120,11 +145,8 @@ function deleteclients(dd) //storing the data function store(eid,logs) { - //for showing data data[eid]= data + JSON.stringify(logs); -//data[eid]= data + JSON.stringify(logs); -data[eid]= logs; - - + + data[eid]=logs; console.log('data with data id' + ' '+ eid +' '+JSON.stringify(data[eid],null,2) ); diff --git a/client.html b/client.html index 447308b..8aa33c5 100644 --- a/client.html +++ b/client.html @@ -18,18 +18,18 @@

communication with socket.io

var socket = io.connect('http://10.200.208.44:8080'); var info; -socket.emit("initial","ok ! Send the data"); +socket.on("filtered data",function (data){ + info = data; + // JSON.stringify(logs,null,2) + console.log('Getting from server' + '
' + info) + document.getElementById("data1").innerHTML += info ; +} ); socket.on('clientsconnected',function(connectedclients){ document.getElementById("data2").innerHTML = connectedclients ; }) -socket.on('Eventlogs',function (data){ - info=data; - // JSON.stringify(logs,null,2) - console.log('Getting from server' + '
' + info) - document.getElementById("data1").innerHTML =JSON.stringify(info,null,2) ; -}) + // socket.on('updates',function (data){ // console.log('from client',data) From 2c669b92be907d6c2cac8e19229057404a8b939d Mon Sep 17 00:00:00 2001 From: keerthana Date: Fri, 3 Nov 2017 14:46:53 +0530 Subject: [PATCH 20/26] 'version-1.2' --- Server.js | 81 ++++++++++++++++++++++++++++++++++++----------------- client.html | 8 ------ 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/Server.js b/Server.js index 518d534..b732cf6 100644 --- a/Server.js +++ b/Server.js @@ -8,7 +8,7 @@ var express = require('express'), connectedclients = {}, objectvalue = {}, filtervar = [], - Eventids = [], + Eventids =[], count = 0, eid, keyfields, @@ -54,34 +54,72 @@ io.on('connection', function (socket) cid = socket.id; //createclientsids(cid); - connectedclients[cid] = 'p3'; - Eventids = objectvalue[connectedclients[cid]]; - console.log('the event ids length'+ Eventids.length+ ' '+ 'they are'+Eventids); + connectedclients[cid] = ['p1','U2']; + var t=0; + var shortestarr=[]; + var shortestarrno; + + for(var j = 0; j < connectedclients[cid].length;j++) + { + + Eventids = objectvalue[connectedclients[cid][j]]; + if(t==0) + { + t = Eventids.length; + shortestarrno = j; + + } + else + { + if( t > Eventids.length) + { + t = Eventids.length; + shortestarrno = j; + + } + + } + + + } + shortestarr = objectvalue[connectedclients[cid][shortestarrno]]; - if(Eventids.length) + for(var k = 0;k < shortestarr.length;k++) { - for(var i = 0;i < Eventids.length; i++) + var val = 0, count = 1; + for(var j = 0; j < connectedclients[cid].length;j++) { - if(data.hasOwnProperty(Eventids[i])) + var compare = objectvalue[ connectedclients[cid][j] ]; + var val,count; + if(j == shortestarrno ) { - console.log('filtered data id to the client'+' '+Eventids[i]+' '+JSON.stringify(data[Eventids[i]],null,2)); - socket.emit('filtered data',JSON.stringify(data[Eventids[i]],null,2)); + continue; + } + val = compare.indexOf(shortestarr[k]); + if(val) + { + count++; + } + else + { + break; } - } + if(count == (connectedclients[cid].length)) + { + if(data.hasOwnProperty(shortestarr[k])) + { + console.log('filtered data id to the client'+' '+shortestarr[k]+' '+JSON.stringify(data[shortestarr[k]],null,2)); + socket.emit('filtered data',JSON.stringify(data[shortestarr[k]],null,2)); + } + } + } - console.log('total clientsconnected'+' '+ count); console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); - // socket.on('initial',function(res) - // { - // console.log('response from client', res); - // socket.emit('Eventlogs', data); - - // }); socket.on('disconnect',function() { @@ -127,14 +165,7 @@ console.log('the log data'+ JSON.stringify(logs,null,2)); res.end(); }); -//creating clients ids -// function createclientsids(d) -// { -// connectedclients[d] = 'p1'; -// console.log('total clientsconnected'+' '+ count); -// console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); -// } -// deleting disconnected clients + function deleteclients(dd) { delete connectedclients[dd]; diff --git a/client.html b/client.html index 8aa33c5..5a2328a 100644 --- a/client.html +++ b/client.html @@ -29,14 +29,6 @@

communication with socket.io

document.getElementById("data2").innerHTML = connectedclients ; }) - - -// socket.on('updates',function (data){ -// console.log('from client',data) -// document.getElementById("data1").innerHTML = data; -// }) - // console.log('from client page'); - //console.log(data); From 6b5e5b9ab4557034cba597d1494ec35c764926c4 Mon Sep 17 00:00:00 2001 From: keerthana Date: Fri, 3 Nov 2017 17:42:49 +0530 Subject: [PATCH 21/26] 'version-1.3' --- Server.js | 45 +++++++++++++++++++++++++++++---------------- client.html | 18 +++++++++++++++--- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Server.js b/Server.js index b732cf6..ebd7893 100644 --- a/Server.js +++ b/Server.js @@ -21,7 +21,7 @@ app.use(bodyParser.text()); server.on('listening', function () { - console.log('server listening'); + console.log('server listening'); }); @@ -44,6 +44,13 @@ app.get('/logdetails', function (req, res) res.sendFile(__dirname + '/client1.html'); }); +//creating clients ids +function createclientsids(d) +{ + connectedclients[d] = ['p1','U2']; + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); +} io.on('connection', function (socket) { @@ -52,18 +59,18 @@ io.on('connection', function (socket) console.log('A user is connected'); console.log(count + ' '+ 'client connected with id ' +' '+ socket.id); cid = socket.id; - //createclientsids(cid); - - connectedclients[cid] = ['p1','U2']; - var t=0; - var shortestarr=[]; - var shortestarrno; - + createclientsids(cid); + // connectedclients[cid] = ['p1','U2']; + var t = 0; + var shortestarr = [];// storing event arrays of filter variable which is having smaller array length + var shortestarrno; + for(var j = 0; j < connectedclients[cid].length;j++) { Eventids = objectvalue[connectedclients[cid][j]]; - if(t==0) + console.log('the Eventids '+ ' ' +Eventids); + if(t == 0) { t = Eventids.length; shortestarrno = j; @@ -82,15 +89,18 @@ io.on('connection', function (socket) } - shortestarr = objectvalue[connectedclients[cid][shortestarrno]]; + + shortestarr = objectvalue[connectedclients[cid][shortestarrno]];// storing the event ids + console.log('the shortest array index and value of that index'+ shortestarrno+' '+shortestarr); + for(var k = 0;k < shortestarr.length;k++) { - var val = 0, count = 1; + var val = 0, count1 = 1; for(var j = 0; j < connectedclients[cid].length;j++) { var compare = objectvalue[ connectedclients[cid][j] ]; - var val,count; + if(j == shortestarrno ) { continue; @@ -98,18 +108,19 @@ io.on('connection', function (socket) val = compare.indexOf(shortestarr[k]); if(val) { - count++; + count1++; } else { break; } } - if(count == (connectedclients[cid].length)) + if(count1 == (connectedclients[cid].length)) { if(data.hasOwnProperty(shortestarr[k])) { - console.log('filtered data id to the client'+' '+shortestarr[k]+' '+JSON.stringify(data[shortestarr[k]],null,2)); + console.log('filtered data id to the client'+' '+ shortestarr[k]+' '+ JSON.stringify(data[shortestarr[k]],null,2)); + socket.emit('eid',shortestarr[k]); socket.emit('filtered data',JSON.stringify(data[shortestarr[k]],null,2)); } @@ -120,7 +131,7 @@ io.on('connection', function (socket) console.log('total clientsconnected'+' '+ count); console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); - + socket.on('disconnect',function() { count-=1; @@ -166,6 +177,8 @@ console.log('the log data'+ JSON.stringify(logs,null,2)); }); + +// deleting disconnected clients function deleteclients(dd) { delete connectedclients[dd]; diff --git a/client.html b/client.html index 5a2328a..c7e06ac 100644 --- a/client.html +++ b/client.html @@ -9,6 +9,7 @@
+

communication with socket.io

@@ -24,11 +25,22 @@

communication with socket.io

console.log('Getting from server' + '
' + info) document.getElementById("data1").innerHTML += info ; } ); +socket.on('eid',function(eventid){ + document.getElementById("data2").innerHTML = eventid; +}); + +// socket.on('clientsconnected',function(connectedclients){ +// document.getElementById("data2").innerHTML = connectedclients ; +// }) + -socket.on('clientsconnected',function(connectedclients){ - document.getElementById("data2").innerHTML = connectedclients ; -}) +// socket.on('updates',function (data){ +// console.log('from client',data) +// document.getElementById("data1").innerHTML = data; +// }) + // console.log('from client page'); + //console.log(data); From 04f08501927bbea6fa5c4e59477bbe4a5051581e Mon Sep 17 00:00:00 2001 From: keerthana Date: Fri, 3 Nov 2017 20:22:23 +0530 Subject: [PATCH 22/26] 'version-1.4' --- Client.txt | 1 + Server.js | 138 +++++++++++++++++++++++++++-------------------------- 2 files changed, 71 insertions(+), 68 deletions(-) create mode 100644 Client.txt diff --git a/Client.txt b/Client.txt new file mode 100644 index 0000000..9e4e303 --- /dev/null +++ b/Client.txt @@ -0,0 +1 @@ +p3,U1 \ No newline at end of file diff --git a/Server.js b/Server.js index ebd7893..389b98a 100644 --- a/Server.js +++ b/Server.js @@ -1,17 +1,14 @@ +var fs = require('fs'); var express = require('express'), app = express(), bodyParser = require('body-parser'), http = require('http'), uid = require('uid'), - data = {}, - logstream = {}, - connectedclients = {}, - objectvalue = {}, - filtervar = [], - Eventids =[], - count = 0, - eid, - keyfields, + data = {}, // for appending the event data + connectedclients = {}, // for appending connectedclients ids as keys with filter variables as values + objectvalue = {}, // storing each eventdata value(say p1, u1,...) in data object with Eventids as values + Eventids =[], // store the Eventids(sy eid1,..) corresponding to the even value (say - p1 / u1 / ip1,...) + count = 0, // total clients connected status cid; var fdata={}; var server = http.createServer(app).listen('8080','10.200.208.44'); @@ -19,12 +16,13 @@ var io = require('socket.io').listen(server); //parsing the text or string app.use(bodyParser.text()); +// server listening function server.on('listening', function () { console.log('server listening'); - }); +// server sends data whenever Client connects to the server app.get('/', function (req, res) { res.send('HOME PAGE'); @@ -47,11 +45,17 @@ app.get('/logdetails', function (req, res) //creating clients ids function createclientsids(d) { - connectedclients[d] = ['p1','U2']; + // reading a file to get the filter variables for the connected client + var data = fs.readFileSync('Client.txt'); + var str = data.toString(); + var arr = str.split(','); + console.log(str); + console.log(arr); + connectedclients[d] = arr; console.log('total clientsconnected'+' '+ count); console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); } - +// Below function starts when socket connection happens io.on('connection', function (socket) { count += 1; @@ -60,40 +64,32 @@ io.on('connection', function (socket) console.log(count + ' '+ 'client connected with id ' +' '+ socket.id); cid = socket.id; createclientsids(cid); - // connectedclients[cid] = ['p1','U2']; var t = 0; - var shortestarr = [];// storing event arrays of filter variable which is having smaller array length - var shortestarrno; + var shortestarr = []; // storing event arrays of filter variable which is having smaller array length + var shortestarrno; for(var j = 0; j < connectedclients[cid].length;j++) - { - + { Eventids = objectvalue[connectedclients[cid][j]]; console.log('the Eventids '+ ' ' +Eventids); if(t == 0) { t = Eventids.length; shortestarrno = j; - } else { if( t > Eventids.length) { t = Eventids.length; - shortestarrno = j; - + shortestarrno = j; } } - - } shortestarr = objectvalue[connectedclients[cid][shortestarrno]];// storing the event ids console.log('the shortest array index and value of that index'+ shortestarrno+' '+shortestarr); - - for(var k = 0;k < shortestarr.length;k++) { var val = 0, count1 = 1; @@ -103,7 +99,7 @@ io.on('connection', function (socket) if(j == shortestarrno ) { - continue; + continue; } val = compare.indexOf(shortestarr[k]); if(val) @@ -115,6 +111,7 @@ io.on('connection', function (socket) break; } } + // checking there is any event id in all the filter Variables array if(count1 == (connectedclients[cid].length)) { if(data.hasOwnProperty(shortestarr[k])) @@ -131,7 +128,7 @@ io.on('connection', function (socket) console.log('total clientsconnected'+' '+ count); console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); - + // Socket disconnection function socket.on('disconnect',function() { count-=1; @@ -146,88 +143,93 @@ io.on('connection', function (socket) app.post('/eventslogs' , function (req, res) { - var logs = {}; - + + var keyfields; //to receive the event data + var logs = {}; // to store the eventdata with unique id + var eid; //to store unique Event id + // parsing the request body keyfields = JSON.parse(req.body); console.log("req.body"+ JSON.stringify(keyfields,1,1)); + + // to store the key with value from received data in new object to append for(var key in keyfields) { logs[key] = keyfields[key]; console.log('key + logs.key'+ key + logs[key]); } + // creating unique id for the event eid = uid(); - + + //Checking for Client is present if (Object.keys(connectedclients).length) { /* filtering checking code comes here */ console.log('clients are connected'); store(eid,logs); } - else { console.log('clients are not connected'); console.log('eid'+ eid) store(eid,logs); } -console.log('the log data'+ JSON.stringify(logs,null,2)); + console.log('the log data'+ JSON.stringify(logs,null,2)); res.end(); }); +// deleting disconnected clients - -// deleting disconnected clients function deleteclients(dd) { + // deleting disconnected clients in the stored connectedclients delete connectedclients[dd]; console.log('total clientsconnected'+' '+ count); console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); } -//storing the data +//Appending the data with Unique Event id function store(eid,logs) { - - data[eid]=logs; - - console.log('data with data id' + ' '+ eid +' '+JSON.stringify(data[eid],null,2) ); - - var temp = logs; - - if(!Object.keys(objectvalue).length) + data[eid]=logs; + console.log('data with data id' + ' '+ eid +' '+JSON.stringify(data[eid],null,2) ); + var temp = logs; + // If there is no property values as key in the object + // Initially(first time) Creating key as data property value and values as unique ids related to the key + if(!Object.keys(objectvalue).length) + { + for(k in temp) + { + console.log('enter into the if case to create a new one'); + // creating an array for each property value + objectvalue[temp[k]] = []; + // adding the new Event id to the array + objectvalue[temp[k]].push(eid); + } + } + // If some property values as key in the object + else + { + for(k in temp) { - - for(k in temp) - { - console.log('enter into the if case to create a new one'); - objectvalue[temp[k]] = []; + // checking the property value or key is present in that object + if(objectvalue.hasOwnProperty(temp[k])) + { + console.log('enter into the has own property'); + // adding the new Event id to the existed array objectvalue[temp[k]].push(eid); - } - - } - else - { - for(k in temp) + // the property value or key is not present in that object + else { - if(objectvalue.hasOwnProperty(temp[k])) - { - console.log('enter into the has own property'); - - objectvalue[temp[k]].push(eid); - } - else - { - console.log('enter into else part of has own property'); - objectvalue[temp[k]] = []; - objectvalue[temp[k]].push(eid); - } + console.log('enter into else part of has own property'); + // creating an array for each property value + objectvalue[temp[k]] = []; + // adding the new Event id to the array + objectvalue[temp[k]].push(eid); } } - - + } console.log('object value'+JSON.stringify(objectvalue,null,2)); - } \ No newline at end of file From b9e7cafd1cd6a1942c00ce26c9148ca7f345b239 Mon Sep 17 00:00:00 2001 From: keerthana Date: Fri, 10 Nov 2017 16:22:52 +0530 Subject: [PATCH 23/26] 'Update_feature' --- Server.js | 148 +++++++++++++++++++++++++++++++++++++++------------- client.html | 17 +----- 2 files changed, 113 insertions(+), 52 deletions(-) diff --git a/Server.js b/Server.js index 389b98a..23083b6 100644 --- a/Server.js +++ b/Server.js @@ -6,13 +6,14 @@ var express = require('express'), uid = require('uid'), data = {}, // for appending the event data connectedclients = {}, // for appending connectedclients ids as keys with filter variables as values - objectvalue = {}, // storing each eventdata value(say p1, u1,...) in data object with Eventids as values - Eventids =[], // store the Eventids(sy eid1,..) corresponding to the even value (say - p1 / u1 / ip1,...) + objectvalue = {}, // storing each eventdata value(say p1, u1,...) in the variable 'data object' with Eventids as values + Eventids =[], // store the Eventids(sy eid1,..) corresponding to the event value (say - p1 / u1 / ip1,...) count = 0, // total clients connected status cid; var fdata={}; var server = http.createServer(app).listen('8080','10.200.208.44'); var io = require('socket.io').listen(server); + //parsing the text or string app.use(bodyParser.text()); @@ -42,19 +43,7 @@ app.get('/logdetails', function (req, res) res.sendFile(__dirname + '/client1.html'); }); -//creating clients ids -function createclientsids(d) -{ - // reading a file to get the filter variables for the connected client - var data = fs.readFileSync('Client.txt'); - var str = data.toString(); - var arr = str.split(','); - console.log(str); - console.log(arr); - connectedclients[d] = arr; - console.log('total clientsconnected'+' '+ count); - console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); -} + // Below function starts when socket connection happens io.on('connection', function (socket) { @@ -88,36 +77,61 @@ io.on('connection', function (socket) } } - shortestarr = objectvalue[connectedclients[cid][shortestarrno]];// storing the event ids + /* storing the event ids of the smallest array among all the filter variables say p1 = [eid1,eid2] , U1 = [eid2,eid3,eid6]. + so the shortestarr will contains the filter variable p1's value */ + + shortestarr = objectvalue[connectedclients[cid][shortestarrno]]; console.log('the shortest array index and value of that index'+ shortestarrno+' '+shortestarr); for(var k = 0;k < shortestarr.length;k++) { var val = 0, count1 = 1; + // connectedclients[cid].length shows the no of filter variables of that particular client. for(var j = 0; j < connectedclients[cid].length;j++) { + // compare is an array contains the eids of that corresponding filter variable + var compare = objectvalue[ connectedclients[cid][j] ]; if(j == shortestarrno ) { + // if the shortest array value is going to compare,skip the remaining steps and move on to next filter variable continue; } + + /* if the eid or (shortestarr[k]) is present in the compare array then it will return the index of that eid + otherwise it will return ' -1 ' as the value */ + val = compare.indexOf(shortestarr[k]); + if(val) { + /* if the compare array has the eid then count variable get incremented by one + -> this one to ensure that all the filter variables array contains that particular eid + if all the variables contains that eid then count1 will have the same value equal to no of filter variables + */ count1++; } else { + /* if any filter variables array does not contain the eid, + then the checking for that particular eid comes to an end + And it goes to check next eid in the shortest arr value + */ break; } } + // checking there is any event id in all the filter Variables array + if(count1 == (connectedclients[cid].length)) { + // after getting eid , checking that eid is present in the data object. if(data.hasOwnProperty(shortestarr[k])) { console.log('filtered data id to the client'+' '+ shortestarr[k]+' '+ JSON.stringify(data[shortestarr[k]],null,2)); + // sending the eid of that event to the client side socket.emit('eid',shortestarr[k]); + // sending the that particular event data to the client socket.emit('filtered data',JSON.stringify(data[shortestarr[k]],null,2)); } @@ -125,8 +139,6 @@ io.on('connection', function (socket) } - console.log('total clientsconnected'+' '+ count); - console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); // Socket disconnection function socket.on('disconnect',function() @@ -137,10 +149,32 @@ io.on('connection', function (socket) deleteclients(socket.id); }); + }); - +//creating clients ids +function createclientsids(d) +{ + // reading a file to get the filter variables for the connected client + var data = fs.readFileSync('Client.txt'); + var str = data.toString(); + var arr = str.split(','); + console.log(str); + console.log(arr); + connectedclients[d] = arr; + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); +} +// deleting disconnected clients + +function deleteclients(dd) +{ + // deleting disconnected clients in the stored connectedclients + delete connectedclients[dd]; + console.log('total clientsconnected'+' '+ count); + console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); +} app.post('/eventslogs' , function (req, res) { @@ -162,32 +196,69 @@ app.post('/eventslogs' , function (req, res) // creating unique id for the event eid = uid(); - //Checking for Client is present - if (Object.keys(connectedclients).length) + /* Checking for Client is present or not. + Object.keys(connectedclients) is an array contains the keys(client ids) of that object 'connectedclients' + */ + if (Object.keys(connectedclients).length) { - /* filtering checking code comes here */ + // /* filtering checking code comes here */ + + for(var obj in connectedclients) + { + var c = 1; + console.log('initial c value'+ c); + var propertyvalues = connectedclients[obj]; + for(var i = 0; i < propertyvalues.length ; i++) + { + + console.log('the property values of the client'+ ' '+ obj +' '+propertyvalues[i]) + console.log('Object.values(logs).indexOf(propertyvalues[i])'+' '+ Object.values(logs).indexOf(propertyvalues[i])); + if(Object.values(logs).indexOf(propertyvalues[i]) > -1) + { + continue; + + } + else + { + c = 0; + console.log('the data is not matching') + break; + + } + + + } + + console.log('the value of c after enter into the loop'+' '+c); + + if(c) + { + console.log('the data is matching '+ ' '+ logs); + // sending the eid of that event to the client side + io.to(obj).emit('eid',eid); + // sending the that particular event data to the client + io.to(obj).emit('filtered data',JSON.stringify(logs,null,2)); + } + + + + } + console.log('clients are connected'); store(eid,logs); } else { console.log('clients are not connected'); - console.log('eid'+ eid) + console.log('eid'+ eid); + store(eid,logs); } console.log('the log data'+ JSON.stringify(logs,null,2)); res.end(); }); -// deleting disconnected clients -function deleteclients(dd) -{ - // deleting disconnected clients in the stored connectedclients - delete connectedclients[dd]; - console.log('total clientsconnected'+' '+ count); - console.log('the connected clients'+ ' '+ JSON.stringify(connectedclients,null,2) ); -} //Appending the data with Unique Event id function store(eid,logs) @@ -195,20 +266,23 @@ function store(eid,logs) data[eid]=logs; console.log('data with data id' + ' '+ eid +' '+JSON.stringify(data[eid],null,2) ); var temp = logs; - // If there is no property values as key in the object - // Initially(first time) Creating key as data property value and values as unique ids related to the key + + /* If there is no property values as key in the object + Initially or for the first time , Creating key as data property value + And values of that will be unique ids ,corresponds to that key */ + if(!Object.keys(objectvalue).length) { for(k in temp) { console.log('enter into the if case to create a new one'); - // creating an array for each property value + // creating a new array for each property value objectvalue[temp[k]] = []; - // adding the new Event id to the array + // adding the Event id to the newly created array objectvalue[temp[k]].push(eid); } } - // If some property values as key in the object + // If some property values as key in the object, it comes to the else part else { for(k in temp) @@ -223,7 +297,7 @@ function store(eid,logs) // the property value or key is not present in that object else { - console.log('enter into else part of has own property'); + console.log('enter into else part of has own property since it has to create a new array for that property value'); // creating an array for each property value objectvalue[temp[k]] = []; // adding the new Event id to the array diff --git a/client.html b/client.html index c7e06ac..3b3a00e 100644 --- a/client.html +++ b/client.html @@ -23,24 +23,11 @@

communication with socket.io

info = data; // JSON.stringify(logs,null,2) console.log('Getting from server' + '
' + info) - document.getElementById("data1").innerHTML += info ; + document.getElementById("data1").innerHTML += info +" " ; } ); socket.on('eid',function(eventid){ - document.getElementById("data2").innerHTML = eventid; + document.getElementById("data2").innerHTML += eventid + " "; }); - -// socket.on('clientsconnected',function(connectedclients){ -// document.getElementById("data2").innerHTML = connectedclients ; -// }) - - - -// socket.on('updates',function (data){ -// console.log('from client',data) -// document.getElementById("data1").innerHTML = data; -// }) - // console.log('from client page'); - //console.log(data); From 2b7266370a53a5c52f792b0f41b6218b08ce34a5 Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 15 Nov 2017 11:36:15 +0530 Subject: [PATCH 24/26] 'Update_Feature' --- Server.js | 157 +++++++++++++++++++++++++++++----------------------- client.html | 20 ++++++- 2 files changed, 107 insertions(+), 70 deletions(-) diff --git a/Server.js b/Server.js index 23083b6..eb791a8 100644 --- a/Server.js +++ b/Server.js @@ -52,94 +52,113 @@ io.on('connection', function (socket) console.log('A user is connected'); console.log(count + ' '+ 'client connected with id ' +' '+ socket.id); cid = socket.id; - createclientsids(cid); + // createclientsids(cid); var t = 0; var shortestarr = []; // storing event arrays of filter variable which is having smaller array length var shortestarrno; + - for(var j = 0; j < connectedclients[cid].length;j++) - { - Eventids = objectvalue[connectedclients[cid][j]]; - console.log('the Eventids '+ ' ' +Eventids); - if(t == 0) - { - t = Eventids.length; - shortestarrno = j; - } - else - { - if( t > Eventids.length) + socket.on('filterVariable',function(da) + { + console.log('the parameters'+ ' '+da); + createclientsids(cid,da); + console.log('the fuction returns again'); + socket.emit('calculate',cid); + console.log('after the socket'); + + }) + socket.on('calculateSmallestArray',function(cid) + { + console.log('its entering into calculate'); + + for(var j = 0; j < connectedclients[cid].length;j++) + { + Eventids = objectvalue[connectedclients[cid][j]]; + console.log('the Eventids '+ ' ' +Eventids); + if(t == 0) { - t = Eventids.length; - shortestarrno = j; + t = Eventids.length; + shortestarrno = j; } + else + { + if( t > Eventids.length) + { + t = Eventids.length; + shortestarrno = j; + } + } } - } - - /* storing the event ids of the smallest array among all the filter variables say p1 = [eid1,eid2] , U1 = [eid2,eid3,eid6]. - so the shortestarr will contains the filter variable p1's value */ - shortestarr = objectvalue[connectedclients[cid][shortestarrno]]; - console.log('the shortest array index and value of that index'+ shortestarrno+' '+shortestarr); - for(var k = 0;k < shortestarr.length;k++) - { - var val = 0, count1 = 1; - // connectedclients[cid].length shows the no of filter variables of that particular client. - for(var j = 0; j < connectedclients[cid].length;j++) + /* storing the event ids of the smallest array among all the filter variables say p1 = [eid1,eid2] , U1 = [eid2,eid3,eid6]. + so the shortestarr will contains the filter variable p1's value */ + + shortestarr = objectvalue[connectedclients[cid][shortestarrno]]; + console.log('the shortest array index and value of that index'+ shortestarrno+' '+shortestarr); + for(var k = 0;k < shortestarr.length;k++) { - // compare is an array contains the eids of that corresponding filter variable - - var compare = objectvalue[ connectedclients[cid][j] ]; - - if(j == shortestarrno ) + var val = 0, count1 = 1; + // connectedclients[cid].length shows the no of filter variables of that particular client. + for(var j = 0; j < connectedclients[cid].length;j++) { - // if the shortest array value is going to compare,skip the remaining steps and move on to next filter variable - continue; - } + // compare is an array contains the eids of that corresponding filter variable - /* if the eid or (shortestarr[k]) is present in the compare array then it will return the index of that eid - otherwise it will return ' -1 ' as the value */ + var compare = objectvalue[ connectedclients[cid][j] ]; - val = compare.indexOf(shortestarr[k]); + if(j == shortestarrno ) + { + // if the shortest array value is going to compare,skip the remaining steps and move on to next filter variable + continue; + } - if(val) - { - /* if the compare array has the eid then count variable get incremented by one - -> this one to ensure that all the filter variables array contains that particular eid - if all the variables contains that eid then count1 will have the same value equal to no of filter variables - */ - count1++; - } - else - { - /* if any filter variables array does not contain the eid, - then the checking for that particular eid comes to an end - And it goes to check next eid in the shortest arr value - */ - break; + /* if the eid or (shortestarr[k]) is present in the compare array then it will return the index of that eid + otherwise it will return ' -1 ' as the value */ + + val = compare.indexOf(shortestarr[k]); + + if(val) + { + /* if the compare array has the eid then count variable get incremented by one + -> this one to ensure that all the filter variables array contains that particular eid + if all the variables contains that eid then count1 will have the same value equal to no of filter variables + */ + count1++; + } + else + { + /* if any filter variables array does not contain the eid, + then the checking for that particular eid comes to an end + And it goes to check next eid in the shortest arr value + */ + break; + } } - } - // checking there is any event id in all the filter Variables array + // checking there is any event id in all the filter Variables array - if(count1 == (connectedclients[cid].length)) - { - // after getting eid , checking that eid is present in the data object. - if(data.hasOwnProperty(shortestarr[k])) + if(count1 == (connectedclients[cid].length)) { - console.log('filtered data id to the client'+' '+ shortestarr[k]+' '+ JSON.stringify(data[shortestarr[k]],null,2)); - // sending the eid of that event to the client side - socket.emit('eid',shortestarr[k]); - // sending the that particular event data to the client - socket.emit('filtered data',JSON.stringify(data[shortestarr[k]],null,2)); + // after getting eid , checking that eid is present in the data object. + if(data.hasOwnProperty(shortestarr[k])) + { + console.log('filtered data id to the client'+' '+ shortestarr[k]+' '+ JSON.stringify(data[shortestarr[k]],null,2)); + // sending the eid of that event to the client side + socket.emit('eid',shortestarr[k]); + // sending the that particular event data to the client + socket.emit('filtered data',JSON.stringify(data[shortestarr[k]],null,2)); + } + } } - - } + + }); + + + // Socket disconnection function socket.on('disconnect',function() { @@ -149,20 +168,22 @@ io.on('connection', function (socket) deleteclients(socket.id); }); + + }); //creating clients ids -function createclientsids(d) +function createclientsids(cid,da) { // reading a file to get the filter variables for the connected client - var data = fs.readFileSync('Client.txt'); + var data = da; var str = data.toString(); var arr = str.split(','); console.log(str); console.log(arr); - connectedclients[d] = arr; + connectedclients[cid] = arr; console.log('total clientsconnected'+' '+ count); console.log('the connected clients individual'+' '+JSON.stringify(connectedclients,null,2) ); } diff --git a/client.html b/client.html index 3b3a00e..8419d2e 100644 --- a/client.html +++ b/client.html @@ -5,7 +5,9 @@ - + + +
@@ -23,11 +25,25 @@

communication with socket.io

info = data; // JSON.stringify(logs,null,2) console.log('Getting from server' + '
' + info) - document.getElementById("data1").innerHTML += info +" " ; + document.getElementById("data1").innerHTML += info + " " ; } ); socket.on('eid',function(eventid){ document.getElementById("data2").innerHTML += eventid + " "; }); +socket.on('calculate',function(cid) +{ + console.log('its entering into client calculate'); + socket.emit('calculateSmallestArray',cid); +}) + + From b8067a877a14268b0885e2335a720f634b731a2f Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 15 Nov 2017 11:40:41 +0530 Subject: [PATCH 25/26] 'Update_Feature' --- Client.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Client.txt diff --git a/Client.txt b/Client.txt deleted file mode 100644 index 9e4e303..0000000 --- a/Client.txt +++ /dev/null @@ -1 +0,0 @@ -p3,U1 \ No newline at end of file From f81f7e1779ca1c2884ab72e85227b6b987dabfee Mon Sep 17 00:00:00 2001 From: keerthana Date: Wed, 15 Nov 2017 16:06:32 +0530 Subject: [PATCH 26/26] 'Merkle_tree' --- Recursive.js | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 Recursive.js diff --git a/Recursive.js b/Recursive.js new file mode 100644 index 0000000..faa2ec2 --- /dev/null +++ b/Recursive.js @@ -0,0 +1,217 @@ +// Importing the file,crypto,uid modules +var fs = require('fs'); +var crypto = require('crypto'); +var uid = require('uid'); +// node object contains the whole merkle tree structure +var Merkle_Tree = {}; +// To store the unique id for each node +var node_Uid; +// To store the Hashes of leaf nodes +var Leaf_hash=[]; + +// Getting data from a text file +var data = fs.readFileSync('testcases.txt'); +var str = data.toString(); +// splitting the data with delimiter as ',' +var Merkle_Proof = str.split(','); +// Creating Hashes for the leaf nodes +for(var i=0; i 0) + { + index = k; + Lkey = key; + + } + + } + console.log('the key and the index'+' ' +Lkey+' '+index); + + + if(index == 1) + { + flag = 1 + Merkle_Proof += ' '+ (Merkle_Tree[Lkey].Right_Node).toString() ; + + + } + else + { + flag = 2 + Merkle_Proof += ' ' + (Merkle_Tree[Lkey].Left_Node).toString(); + + + + } + + var hash = crypto.createHash('sha256'); + var Append_hash1; + if(flag == 1) + { + Append_hash1 = check + Merkle_Tree[Lkey].Right_Node ; + } + else + { + Append_hash1 = check + Merkle_Tree[Lkey].Left_Node ; + } + + hash.update(Append_hash1); + hex = hash.digest('hex'); + + +console.log('the value of hex '+ hex); +// Auditprocess function invokes , till the checking(hash) value does not match the root value, + if(hex != r) + { + auditprocess(hex); + } + +} + + +// the arr contains all the related hashes to calculate merkle proof +console.log('The proof of containing the record 1'+ Merkle_Proof); + + +