diff --git a/example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js b/example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js index 97020a0..ef751c7 100644 --- a/example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js +++ b/example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js @@ -1,10 +1,10 @@ var ipc=require('../../../node-ipc'); /***************************************\ - * + * * You should start both hello and world * then you will see them communicating. - * + * * *************************************/ ipc.config.id = 'goodbye'; @@ -41,4 +41,4 @@ ipc.connectToNet( } ); } -); \ No newline at end of file +); diff --git a/example/TCPSocket/Multi-Client-Broadcast/hello-client.js b/example/TCPSocket/Multi-Client-Broadcast/hello-client.js index 3d01fb5..69bc727 100644 --- a/example/TCPSocket/Multi-Client-Broadcast/hello-client.js +++ b/example/TCPSocket/Multi-Client-Broadcast/hello-client.js @@ -1,10 +1,10 @@ var ipc=require('../../../node-ipc'); /***************************************\ - * + * * You should start both hello and world * then you will see them communicating. - * + * * *************************************/ ipc.config.id = 'hello'; @@ -36,7 +36,7 @@ ipc.connectToNet( ipc.of.world.on( 'app.message', function(data){ - ipc.log('got a message from world : '.debug, data.messgae); + ipc.log('got a message from world : '.debug, data.message); } ); ipc.of.world.on( @@ -47,4 +47,4 @@ ipc.connectToNet( } ); } -); \ No newline at end of file +); diff --git a/example/TCPSocket/rawBuffer/hello-client.js b/example/TCPSocket/rawBuffer/hello-client.js new file mode 100644 index 0000000..4f8831e --- /dev/null +++ b/example/TCPSocket/rawBuffer/hello-client.js @@ -0,0 +1,35 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'hello'; +ipc.config.retry= 1500; +ipc.config.rawBuffer=true; +ipc.config.encoding='ascii'; + +ipc.connectToNet( + 'world', + function(){ + ipc.of.world.on( + 'connect', + function(){ + ipc.log('## connected to world ##'.rainbow, ipc.config.delay); + ipc.of.world.emit( + 'hello' + ) + } + ); + + ipc.of.world.on( + 'data', + function(data){ + ipc.log('got a message from world : '.debug, data,data.toString()); + } + ); + } +); diff --git a/example/TCPSocket/rawBuffer/world.server.js b/example/TCPSocket/rawBuffer/world.server.js new file mode 100644 index 0000000..b042c96 --- /dev/null +++ b/example/TCPSocket/rawBuffer/world.server.js @@ -0,0 +1,40 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'world'; +ipc.config.retry= 1500; +ipc.config.rawBuffer=true; +ipc.config.encoding='ascii'; + +ipc.serveNet( + function(){ + ipc.server.on( + 'connect', + function(socket){ + ipc.server.emit( + socket, + 'hello' + ); + } + ); + + ipc.server.on( + 'data', + function(data,socket){ + ipc.log('got a message'.debug, data,data.toString()); + ipc.server.emit( + socket, + 'goodbye' + ); + } + ); + } +); + +ipc.server.start(); diff --git a/example/UDPSocket/rawBuffer/hello-client.js b/example/UDPSocket/rawBuffer/hello-client.js new file mode 100644 index 0000000..0da683b --- /dev/null +++ b/example/UDPSocket/rawBuffer/hello-client.js @@ -0,0 +1,35 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'hello'; +ipc.config.retry= 1500; +ipc.config.rawBuffer=true; +ipc.config.encoding='ascii'; + +ipc.serveNet( + 8001, //we set the port here because the world server is already using the default of 8000. So we can not bind to 8000 while world is using it. + 'udp4', + function(){ + ipc.server.on( + 'data', + function(data){ + ipc.log('got a message from world '.debug, data, data.toString()); + } + ); + ipc.server.emit( + { + address : 'localhost', + port : ipc.config.networkPort + }, + 'hello' + ); + } +); + +ipc.server.start(); diff --git a/example/UDPSocket/rawBuffer/world.server.js b/example/UDPSocket/rawBuffer/world.server.js new file mode 100644 index 0000000..a425a0d --- /dev/null +++ b/example/UDPSocket/rawBuffer/world.server.js @@ -0,0 +1,43 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * UDP Client is really a UDP server + * + * 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'; +ipc.config.retry= 1500; +ipc.config.rawBuffer=true; +ipc.config.encoding='ascii'; + +ipc.serveNet( + 'udp4', + function(){ + ipc.server.on( + 'data', + function(data,socket){ + ipc.log('got a message'.debug, data,data.toString()); + ipc.server.emit( + socket, + 'goodbye' + ); + } + ); + } +); + +ipc.server.start(); diff --git a/example/unixSocket/basic/hello-client.js b/example/unixSocket/basic/hello-client.js index 83d9234..5e1478c 100644 --- a/example/unixSocket/basic/hello-client.js +++ b/example/unixSocket/basic/hello-client.js @@ -1,10 +1,10 @@ var ipc=require('../../../node-ipc'); /***************************************\ - * + * * You should start both hello and world * then you will see them communicating. - * + * * *************************************/ ipc.config.id = 'hello'; diff --git a/lib/client.js b/lib/client.js index e18e4bf..c35c00b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,7 @@ var net = require('net'), eventParser = require('../lib/eventParser.js'), - pubsub = require('event-pubsub'); + pubsub = require('event-pubsub'), + Message = require('js-message'); function init(config,log){ var client={ @@ -12,38 +13,36 @@ function init(config,log){ retriesRemaining:config.maxRetries||0 } new pubsub(client); - + return client; } function emit(type,data){ this.log('dispatching event to '.debug, this.id.variable, this.path.variable,' : ', type.data,',', data); - if(!data) - data=false; + + var message=new Message; + message.type=type; + message.data=data; + if(this.config.rawBuffer){ - data=new Buffer(type,this.encoding); + message=new Buffer(type,this.encoding); }else{ - data=eventParser.format( - { - type:type, - data:data - } - ); + message=eventParser.format(message); } - this.socket.write(data); + this.socket.write(message); }; function connect(){ //init client object for scope persistance especially inside of socket events. var client=this; - + client.log('requested connection to '.debug, client.id.variable, client.path.variable); if(!this.path){ client.log('\n\n######\nerror: '.error, client.id .info,' client has not specified socket path it wishes to connect to.'.error); return; } - + if(!client.port){ client.log('Connecting client on Unix Socket :'.debug, client.path.variable); client.socket = net.connect( @@ -60,16 +59,16 @@ function connect(){ } ); } - + client.socket.setEncoding(this.config.encoding); - + client.socket.on( 'error', function(err){ client.log('\n\n######\nerror: '.error, err); } ); - + client.socket.on( 'connect', function(){ @@ -78,12 +77,12 @@ function connect(){ client.log('retrying reset') } ); - + client.socket.on( 'close', function(){ client.log('connection closed'.notice ,client.id.variable , client.path.variable, client.retriesRemaining+' tries remaining of '+client.config.maxRetries); - + if( client.config.stopRetrying || client.retriesRemaining<1 @@ -93,15 +92,15 @@ function connect(){ 'exceeded connection rety amount of'.warn, " or stopRetrying flag set." ); - + client.socket.destroy(); client=undefined; - + return; } - + client.isRetrying=true; - + setTimeout( ( function(client){ @@ -114,18 +113,18 @@ function connect(){ if(!client.isRetrying) client.retriesRemaining=client.config.maxRetries; }, - 100 + 100 ) } } )(client), client.config.retry ); - + client.trigger('disconnect'); } ); - + client.socket.on( 'data', function(data) { @@ -140,26 +139,26 @@ function connect(){ if(!this.ipcBuffer) this.ipcBuffer=''; - + data=(this.ipcBuffer+=data); - + if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){ client.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice); return; } - + this.ipcBuffer=''; - + var events = eventParser.parse(data); var eCount = events.length; for(var i=0; i0){ - var e=JSON.parse(data.shift()); - server.log('received event of : '.debug,e.type.data,e.data); - - if(e.data.id) - sock.id=e.data.id; - + var message=new Message; + message.load(data.shift()); + + server.log('received event of : '.debug,message.type.data,message.data); + + if(message.data.id) + sock.id=message.data.id; + server.trigger( - e.type, - e.data, + message.type, + message.data, sock ); } } ); - + socket.on( 'message', function(msg,rinfo) { @@ -233,12 +224,12 @@ function init(path,config,log,port){ socket.emit('data',data,rinfo); } ); - + server.trigger( 'connect', socket ); - + if(server.config.rawBuffer){ return; } @@ -247,28 +238,28 @@ function init(path,config,log,port){ 'get.events.broadcasting', socket ); - + server.trigger( 'get.events.listening', socket ); } - + function started(socket){ server.onStart(socket) } - + if(!port){ server.log('starting server as'.debug, 'Unix Socket'.variable); server.server.listen( server.path, started ); - + server.server.maxConnections=server.maxConnections; return; } - + if(!server.udp4 && !server.udp4){ server.log('starting server as'.debug, 'TCP'.variable); server.server.listen( @@ -278,13 +269,13 @@ function init(path,config,log,port){ ); return; } - + server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable); server.server.bind( - server.port, + server.port, server.path ); - + started( { address : server.path, @@ -297,9 +288,9 @@ function init(path,config,log,port){ ); } }; - + new pubsub(server); - + server.on( 'get.events.broadcasting', function(socket){ @@ -313,7 +304,7 @@ function init(path,config,log,port){ ); } ); - + server.on( 'get.events.listening', function(socket){ @@ -326,35 +317,35 @@ function init(path,config,log,port){ } ); } - ) - + ) + server.on( - 'close', + 'close', function(){ for(var i=0, count=server.sockets.length; i=0.1.90" @@ -27,7 +27,7 @@ "shasum": "2423fe6678ac0c5dae8852e5d0e5be08c997abcc", "tarball": "http://registry.npmjs.org/colors/-/colors-0.6.2.tgz" }, - "_from": "colors@~0.6.2", + "_from": "colors@>=0.6.2 <0.7.0", "_npmVersion": "1.2.30", "_npmUser": { "name": "marak", diff --git a/node_modules/event-pubsub/package.json b/node_modules/event-pubsub/package.json index 7b04093..2c109b0 100644 --- a/node_modules/event-pubsub/package.json +++ b/node_modules/event-pubsub/package.json @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/RIAEvangelist/event-pubsub.git" + "url": "git+https://github.com/RIAEvangelist/event-pubsub.git" }, "keywords": [ "event", @@ -33,7 +33,7 @@ "shasum": "c81c49b101cdb4892d8fa2631b443184db2de6aa", "tarball": "http://registry.npmjs.org/event-pubsub/-/event-pubsub-1.0.3.tgz" }, - "_from": "event-pubsub@~1.0.3", + "_from": "event-pubsub@>=1.0.3 <1.1.0", "_npmVersion": "1.4.3", "_npmUser": { "name": "riaevangelist", diff --git a/node_modules/node-cmd/package.json b/node_modules/node-cmd/package.json index 711c3a2..23c7610 100644 --- a/node_modules/node-cmd/package.json +++ b/node_modules/node-cmd/package.json @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/RIAEvangelist/node-cmd.git" + "url": "git+https://github.com/RIAEvangelist/node-cmd.git" }, "keywords": [ "commandline", @@ -29,10 +29,25 @@ "url": "https://github.com/RIAEvangelist/node-cmd/issues" }, "homepage": "https://github.com/RIAEvangelist/node-cmd", - "readme": "#node-cmd\n-\n*Node.js commandline/terminal interface.* \n\nSimple commandline or terminal interface to allow you to run cli or bash style commands as if you were in the terminal.\n\nRun commands asynchronously, and if needed can get the output as a string.\n\n#Methods\n-\n\n|method | arguments | functionality |\n|-------|-----------|---------------|\n|run | command | runs a command asynchronously|\n|get | command,callback | runs a command asynchronously, when the command is complete all of the stdout will be passed to the callback|\n\n\n#Examples\n-\n\n var cmd=require('node-cmd');\n \n cmd.get(\n 'pwd',\n function(data){\n console.log('the current working dir is : ',data)\n }\n );\n \n cmd.run('touch example.created.file');\n \n cmd.get(\n 'ls',\n function(data){\n console.log('the current dir contains these files :\\n\\n',data)\n }\n );\n\n", - "readmeFilename": "README.md", "gitHead": "a003426996e8594af31a6486cfb7d28d0a547bc9", "_id": "node-cmd@1.0.2", "_shasum": "89cdb50181476cdd127763d5c8514499fe3c038d", - "_from": "node-cmd@~1.0.1" + "_from": "node-cmd@>=1.0.1 <1.1.0", + "_npmVersion": "1.4.23", + "_npmUser": { + "name": "riaevangelist", + "email": "brandon@diginow.it" + }, + "maintainers": [ + { + "name": "riaevangelist", + "email": "brandon@1942design.com" + } + ], + "dist": { + "shasum": "89cdb50181476cdd127763d5c8514499fe3c038d", + "tarball": "http://registry.npmjs.org/node-cmd/-/node-cmd-1.0.2.tgz" + }, + "_resolved": "https://registry.npmjs.org/node-cmd/-/node-cmd-1.0.2.tgz", + "readme": "ERROR: No README data found!" } diff --git a/package.json b/package.json index 86cccd7..6beefc3 100644 --- a/package.json +++ b/package.json @@ -7,15 +7,12 @@ "example": "example" }, "dependencies": { - "event-pubsub": "~1.0.3", "colors": "~0.6.2", + "event-pubsub": "~1.0.3", + "js-message": "*", "node-cmd": "~1.0.1" }, - "devDependencies": { - "colors": "*", - "event-pubsub": "*", - "node-cmd": "*" - }, + "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },