diff --git a/.brackets.json b/.brackets.json deleted file mode 100644 index 42bf8a6..0000000 --- a/.brackets.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "sbruchmann.staticpreview.basepath": "/home/bmiller/git/node-ipc/" -} diff --git a/README.md b/README.md index 2ebf593..eddf091 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ A great solution for **Neural Networking** in Node.JS npm info : [See npm trends and stats for node-ipc](http://npm-stat.com/charts.html?package=node-ipc&author=&from=&to=) -[![NPM](https://nodei.co/npm/node-ipc.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/node-ipc/) +[![NPM](https://nodei.co/npm/node-ipc.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/node-ipc/) +[![Package Quality](http://npm.packagequality.com/badge/node-ipc.png)](http://packagequality.com/#?package=node-ipc) ![node-ipc npm version](https://img.shields.io/npm/v/node-ipc.svg) ![supported node version for node-ipc](https://img.shields.io/node/v/node-ipc.svg) ![total npm downloads for node-ipc](https://img.shields.io/npm/dt/node-ipc.svg) ![monthly npm downloads for node-ipc](https://img.shields.io/npm/dm/node-ipc.svg) ![npm licence for node-ipc](https://img.shields.io/npm/l/node-ipc.svg) [![RIAEvangelist](https://avatars3.githubusercontent.com/u/369041?v=3&s=100)](https://github.com/RIAEvangelist) @@ -150,7 +151,7 @@ You can override any of these settings by requireing colors and setting the them `ipc.connectTo(id,path,callback);` -Used for connecting as a client to local Unix Sockets and Windows Sockets. ***This is the fastst way for processes on the same machine to communicate*** because it bypasses the network card which TCP and UDP must both use. +Used for connecting as a client to local Unix Sockets and Windows Sockets. ***This is the fastest way for processes on the same machine to communicate*** because it bypasses the network card which TCP and UDP must both use. | variable | required | definition | |----------|----------|------------| @@ -354,8 +355,8 @@ Used to create TCP, TLS or UDP Socket Server to which Clients can bind or other | variable | required | definition | |----------|----------|------------| | host | optional | If not specified this defaults to the first address in os.networkInterfaces(). For TCP, TLS & UDP servers this is most likely going to be 127.0.0.1 or ::1 | -| port | optional | The port on wunich the TCP, UDP, or TLS Socket server will be bound, this defaults to 8000 if not specified | -| UDPType | optional | If set this will create the server as a UDP socket. 'udp4' or 'udp6' are valid values. This defaults to not being set. +| port | optional | The port on which the TCP, UDP, or TLS Socket server will be bound, this defaults to 8000 if not specified | +| UDPType | optional | If set this will create the server as a UDP socket. 'udp4' or 'udp6' are valid values. This defaults to not being set. When using udp6 make sure to specify a valid IPv6 host, like ` ::1 ` | | callback | optional | Function to be called when the server is created | ***examples*** arguments can be ommitted solong as they are still in order. @@ -440,6 +441,14 @@ or specifying everything UDP | ipc.of | This is where socket connection refrences will be stored when connecting to them as a client via the `ipc.connectTo` or `iupc.connectToNet`. They will be stored based on the ID used to create them, eg : ipc.of.mySocket| | ipc.server| This is a refrence to the server created by `ipc.serve` or `ipc.serveNet`| +---- +### IPC Server Methods + +| method | definition | +|-----------|------------| +|start| start serving need top call ` serve ` or ` serveNet ` first to set up the server | +|stop| close the server and stop serving | + ---- ### IPC Events diff --git a/example/TCPSocket/basic/world-server.js b/example/TCPSocket/basic/world-server.js index 8176d61..7c8c855 100644 --- a/example/TCPSocket/basic/world-server.js +++ b/example/TCPSocket/basic/world-server.js @@ -9,6 +9,7 @@ var ipc=require('../../../node-ipc'); ipc.config.id = 'world'; ipc.config.retry= 1500; +ipc.config.maxConnections=1; ipc.serveNet( function(){ @@ -33,4 +34,11 @@ ipc.serveNet( } ); +ipc.server.on( + 'error', + function(err){ + ipc.log('Got an ERROR!'.warn,err) + } +) + ipc.server.start(); diff --git a/example/TLSSocket/Multi-Client-Broadcast-basic/world-server.js b/example/TLSSocket/Multi-Client-Broadcast-basic/world-server.js index 7442d85..6214040 100644 --- a/example/TLSSocket/Multi-Client-Broadcast-basic/world-server.js +++ b/example/TLSSocket/Multi-Client-Broadcast-basic/world-server.js @@ -10,8 +10,8 @@ var ipc=require('../../../node-ipc'); ipc.config.id = 'world'; ipc.config.retry= 1500; ipc.config.tls={ - public: '../../../local-node-ipc-certs/server.pub', - private: '../../../local-node-ipc-certs/private/server.key' + public: __dirname+'/../../../local-node-ipc-certs/server.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/server.key' } var messages={ diff --git a/example/TLSSocket/basic-more-secure/hello-client.js b/example/TLSSocket/basic-more-secure/hello-client.js index 4104d26..5f40b04 100644 --- a/example/TLSSocket/basic-more-secure/hello-client.js +++ b/example/TLSSocket/basic-more-secure/hello-client.js @@ -10,11 +10,11 @@ var ipc=require('../../../node-ipc'); ipc.config.id = 'hello'; ipc.config.retry= 1500; ipc.config.tls={ - private: '../../../local-node-ipc-certs/private/client.key', - public: '../../../local-node-ipc-certs/client.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/client.key', + public: __dirname+'/../../../local-node-ipc-certs/client.pub', rejectUnauthorized:false, trustedConnections: [ - '../../../local-node-ipc-certs/server.pub' + __dirname+'/../../../local-node-ipc-certs/server.pub' ] }; diff --git a/example/TLSSocket/basic-more-secure/world-server.js b/example/TLSSocket/basic-more-secure/world-server.js index a893487..f1762dc 100644 --- a/example/TLSSocket/basic-more-secure/world-server.js +++ b/example/TLSSocket/basic-more-secure/world-server.js @@ -10,13 +10,13 @@ var ipc=require('../../../node-ipc'); ipc.config.id = 'world'; ipc.config.retry= 1500; ipc.config.tls={ - public: '../../../local-node-ipc-certs/server.pub', - private: '../../../local-node-ipc-certs/private/server.key', - dhparam: '../../../local-node-ipc-certs/private/dhparam.pem', + public: __dirname+'/../../../local-node-ipc-certs/server.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/server.key', + dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem', requestCert: true, rejectUnauthorized:false, trustedConnections: [ - '../../../local-node-ipc-certs/client.pub' + __dirname+'/../../../local-node-ipc-certs/client.pub' ] } diff --git a/example/TLSSocket/basic-most-secure/hello-client.js b/example/TLSSocket/basic-most-secure/hello-client.js index 2bfced2..1188cfb 100644 --- a/example/TLSSocket/basic-most-secure/hello-client.js +++ b/example/TLSSocket/basic-most-secure/hello-client.js @@ -11,11 +11,11 @@ ipc.config.id = 'hello'; ipc.config.retry= 1500; ipc.config.networkHost='localhost'; ipc.config.tls={ - private: '../../../local-node-ipc-certs/private/client.key', - public: '../../../local-node-ipc-certs/client.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/client.key', + public: __dirname+'/../../../local-node-ipc-certs/client.pub', rejectUnauthorized:true, trustedConnections: [ - '../../../local-node-ipc-certs/server.pub' + __dirname+'/../../../local-node-ipc-certs/server.pub' ] }; diff --git a/example/TLSSocket/basic-most-secure/world-server.js b/example/TLSSocket/basic-most-secure/world-server.js index e44b4c9..4af0315 100644 --- a/example/TLSSocket/basic-most-secure/world-server.js +++ b/example/TLSSocket/basic-most-secure/world-server.js @@ -11,13 +11,13 @@ ipc.config.id = 'world'; ipc.config.retry= 1500; ipc.config.networkHost='localhost'; ipc.config.tls={ - public: '../../../local-node-ipc-certs/server.pub', - private: '../../../local-node-ipc-certs/private/server.key', - dhparam: '../../../local-node-ipc-certs/private/dhparam.pem', + public: __dirname+'/../../../local-node-ipc-certs/server.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/server.key', + dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem', requestCert: true, rejectUnauthorized:true, trustedConnections: [ - '../../../local-node-ipc-certs/client.pub' + __dirname+'/../../../local-node-ipc-certs/client.pub' ] } diff --git a/example/TLSSocket/basic/world-server.js b/example/TLSSocket/basic/world-server.js index a78da8a..31d4798 100644 --- a/example/TLSSocket/basic/world-server.js +++ b/example/TLSSocket/basic/world-server.js @@ -10,8 +10,8 @@ var ipc=require('../../../node-ipc'); ipc.config.id = 'world'; ipc.config.retry= 1500; ipc.config.tls={ - public: '../../../local-node-ipc-certs/server.pub', - private: '../../../local-node-ipc-certs/private/server.key' + public: __dirname+'/../../../local-node-ipc-certs/server.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/server.key' } ipc.serveNet( diff --git a/example/TLSSocket/basicSync/world-server.js b/example/TLSSocket/basicSync/world-server.js index 8ae2325..d6128b5 100644 --- a/example/TLSSocket/basicSync/world-server.js +++ b/example/TLSSocket/basicSync/world-server.js @@ -11,8 +11,8 @@ ipc.config.id = 'world'; ipc.config.retry= 1500; ipc.config.sync= true; ipc.config.tls={ - public: '../../../local-node-ipc-certs/server.pub', - private: '../../../local-node-ipc-certs/private/server.key' + public: __dirname+'/../../../local-node-ipc-certs/server.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/server.key' } ipc.serveNet( diff --git a/example/TLSSocket/rawBuffer-only-works-with-most-secure/hello-client.js b/example/TLSSocket/rawBuffer-only-works-with-most-secure/hello-client.js index b893444..f4cac3e 100644 --- a/example/TLSSocket/rawBuffer-only-works-with-most-secure/hello-client.js +++ b/example/TLSSocket/rawBuffer-only-works-with-most-secure/hello-client.js @@ -14,11 +14,11 @@ ipc.config.encoding='ascii'; ipc.config.networkHost='localhost'; ipc.config.tls={ - private: '../../../local-node-ipc-certs/private/client.key', - public: '../../../local-node-ipc-certs/client.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/client.key', + public: __dirname+'/../../../local-node-ipc-certs/client.pub', rejectUnauthorized:true, trustedConnections: [ - '../../../local-node-ipc-certs/server.pub' + __dirname+'/../../../local-node-ipc-certs/server.pub' ] }; diff --git a/example/TLSSocket/rawBuffer-only-works-with-most-secure/world.server.js b/example/TLSSocket/rawBuffer-only-works-with-most-secure/world.server.js index d4053ea..f8394be 100644 --- a/example/TLSSocket/rawBuffer-only-works-with-most-secure/world.server.js +++ b/example/TLSSocket/rawBuffer-only-works-with-most-secure/world.server.js @@ -14,13 +14,13 @@ ipc.config.encoding='ascii'; ipc.config.networkHost='localhost'; ipc.config.tls={ - public: '../../../local-node-ipc-certs/server.pub', - private: '../../../local-node-ipc-certs/private/server.key', - dhparam: '../../../local-node-ipc-certs/private/dhparam.pem', + public: __dirname+'/../../../local-node-ipc-certs/server.pub', + private: __dirname+'/../../../local-node-ipc-certs/private/server.key', + dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem', requestCert: true, rejectUnauthorized:true, trustedConnections: [ - '../../../local-node-ipc-certs/client.pub' + __dirname+'/../../../local-node-ipc-certs/client.pub' ] } diff --git a/example/UDPSocket/basic/world-server.js b/example/UDPSocket/basic/world-server.js index 75d46a9..b305d4e 100644 --- a/example/UDPSocket/basic/world-server.js +++ b/example/UDPSocket/basic/world-server.js @@ -1,22 +1,22 @@ var ipc=require('../../../node-ipc'); /***************************************\ - * + * * UDP Client is really a UDP server - * - * Dedicated UDP sockets on the same + * + * Dedicated UDP sockets on the same * machine can not be bound to in the * traditional client/server method - * + * * Every UDP socket is it's own UDP server * And so must have a unique port on its * machine, unlike TCP or Unix Sockts * which can share on the same machine. - * + * * Since there is no open client server * relationship, you should start world * first and then hello. - * + * ***************************************/ ipc.config.id = 'world'; @@ -45,4 +45,4 @@ ipc.serveNet( -ipc.server.start(); \ No newline at end of file +ipc.server.start(); diff --git a/lib/socketServer.js b/lib/socketServer.js index 92a858b..a4c1163 100644 --- a/lib/socketServer.js +++ b/lib/socketServer.js @@ -78,6 +78,9 @@ function init(path,config,log,port){ socket ); }, + stop:function(){ + server.server.close(); + }, start : function(){ if(!this.path){ server.log('Socket Server Path not specified, refusing to start'.warn); @@ -138,6 +141,7 @@ function init(path,config,log,port){ socket.address, function(err, bytes) { if(err){ + server.log('error writing data to socket'.warn,err); server.trigger( 'error', function(err){ @@ -161,6 +165,20 @@ function init(path,config,log,port){ ); } + server.server.on( + 'error', + function(err){ + server.log('server error'.warn,err); + + server.trigger( + 'error', + err + ) + } + ); + + server.server.maxConnections=server.config.maxConnections; + function serverCreated(socket) { server.sockets.push(socket); @@ -181,6 +199,8 @@ function init(path,config,log,port){ socket.on( 'error', function(err){ + server.log('server socket error'.warn,err); + server.trigger('error',err); } ); @@ -275,11 +295,10 @@ function init(path,config,log,port){ started ); - server.server.maxConnections=server.maxConnections; return; } - if(!server.udp4 && !server.udp4){ + if(!server.udp4 && !server.udp6){ server.log('starting server as'.debug, (server.config.tls?'TLS':'TCP').variable); server.server.listen( server.port, diff --git a/package.json b/package.json index 5aaafa3..a604372 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-ipc", - "version": "5.0.0", + "version": "5.2.0", "description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.", "main": "node-ipc.js", "directories": { diff --git a/testHarness/readme.md b/testHarness/readme.md deleted file mode 100644 index fe2c214..0000000 --- a/testHarness/readme.md +++ /dev/null @@ -1,9 +0,0 @@ -#node-ipc test harness -***TestHarness was intended to be run on linux.*** -*the test.js file is intended to start and run all of the files in the test folder* - -A full regression test should be done before each release to npm to insure that no expected or previously documented bugs pop up again. -This will also help to ensure that each new release does not create any additional bugs. However, it can never fully ensure no new bugs will be created. -Any bug that is reported and testable, which should be 99.9% of bugs, should have a test written and added to the test folder after fixing. - -> Written with [StackEdit](https://stackedit.io/). \ No newline at end of file diff --git a/testHarness/test.js b/testHarness/test.js deleted file mode 100644 index bca7e3c..0000000 --- a/testHarness/test.js +++ /dev/null @@ -1,170 +0,0 @@ -var ipc = require('../node-ipc'), - cmd = require('node-cmd'), - fs = require('fs'), - tests = {}, - testCount=0, - fails=[], - passes=[], - debug=true; - -ipc.config.id = 'testHarness'; - -ipc.serve( - function(){ - - } -); - -ipc.server.on( - 'pass', - function(test,socket){ - ipc.log(socket.id.good,'passed',test.data); - tests[socket.id].pass.push(test); - passes.push(test); - } -); - -ipc.server.on( - 'fail', - function(test,socket){ - ipc.log(socket.id.warn,'failed',test.data); - tests[socket.id].fail.push(test); - fails.push(test); - } -); - -ipc.server.on( - 'start.test', - function(data,socket){ - - socket.id=data.id; - - if(!data.id){ - ipc.log('start.test duration not passed for unknown test, so failing test'.error); - socket.destroy(); - return; - } - - if(!data.duration){ - ipc.log(data.id.notice, 'start.test duration not passed, so failing test'.error); - ipc.disconnect(data.id); - return; - } - - ipc.log(data.id.notice, 'started'.debug); - - tests[data.id].started=true; - clearTimeout( - tests[data.id].delay - ); - - tests[data.id].delay=setTimeout( - ( - function(test){ - return function(){ - ipc.log(test.warn," failed to complete ".error); - tests[test].fail.push('end.test'); - fails.push(test+' >> end.test'); - testCount--; - tests[socket.id].delay=null; - checkComplete(); - } - } - )(data.id), - data.duration - ) - } -); - -ipc.server.on( - 'end.test', - function(data,socket){ - ipc.log(socket.id.notice, 'completed'.debug); - clearTimeout( - tests[socket.id].delay - ); - - tests[socket.id].delay=null; - - testCount--; - checkComplete(); - } -); - -ipc.log('TestHarness started.'.debug, 'Loading Tests.'.notice); - -ipc.server.define.listen['start.test']='This event should be called when a test is starting. It accepts an object with test details including the test id and duration'; -ipc.server.define.listen['end.test']='This event should be called when a test is completed.'; -ipc.server.define.listen['pass']='This event should be called when a test has passed, it accepts the name of the test portion which passed'; -ipc.server.define.listen['fail']='This event should be called when a test has failed, it accepts the name of the test portion which failed'; - -ipc.server.start(); - -fs.readdir( - 'tests', - function(err,testFolders){ - if(err){ - ipc.log(err,'You must execute the testHarness from the testHarness directory'.error) - return; - } - testCount=testFolders.length; - - for(var i =0; i> start.test'); - testCount--; - checkComplete(); - } - } - )(testFolders[i]), - 1000 - ) - }; - - runTests(testFolders[i]) - } - } -); - -function runTests(dir){ - fs.readdir( - 'tests/'+dir, - function(err,testFiles){ - if(err){ - ipc.log(err,'You must execute the testHarness from the testHarness directory'.error) - return; - } - for(var i =0; i