added js-message dep and rawBuffer examples
This commit is contained in:
parent
7f06fe6a14
commit
ac714e91a4
14 changed files with 313 additions and 154 deletions
|
@ -1,10 +1,10 @@
|
||||||
var ipc=require('../../../node-ipc');
|
var ipc=require('../../../node-ipc');
|
||||||
|
|
||||||
/***************************************\
|
/***************************************\
|
||||||
*
|
*
|
||||||
* You should start both hello and world
|
* You should start both hello and world
|
||||||
* then you will see them communicating.
|
* then you will see them communicating.
|
||||||
*
|
*
|
||||||
* *************************************/
|
* *************************************/
|
||||||
|
|
||||||
ipc.config.id = 'goodbye';
|
ipc.config.id = 'goodbye';
|
||||||
|
@ -41,4 +41,4 @@ ipc.connectToNet(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
var ipc=require('../../../node-ipc');
|
var ipc=require('../../../node-ipc');
|
||||||
|
|
||||||
/***************************************\
|
/***************************************\
|
||||||
*
|
*
|
||||||
* You should start both hello and world
|
* You should start both hello and world
|
||||||
* then you will see them communicating.
|
* then you will see them communicating.
|
||||||
*
|
*
|
||||||
* *************************************/
|
* *************************************/
|
||||||
|
|
||||||
ipc.config.id = 'hello';
|
ipc.config.id = 'hello';
|
||||||
|
@ -36,7 +36,7 @@ ipc.connectToNet(
|
||||||
ipc.of.world.on(
|
ipc.of.world.on(
|
||||||
'app.message',
|
'app.message',
|
||||||
function(data){
|
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(
|
ipc.of.world.on(
|
||||||
|
@ -47,4 +47,4 @@ ipc.connectToNet(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
35
example/TCPSocket/rawBuffer/hello-client.js
Normal file
35
example/TCPSocket/rawBuffer/hello-client.js
Normal file
|
@ -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());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
40
example/TCPSocket/rawBuffer/world.server.js
Normal file
40
example/TCPSocket/rawBuffer/world.server.js
Normal file
|
@ -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();
|
35
example/UDPSocket/rawBuffer/hello-client.js
Normal file
35
example/UDPSocket/rawBuffer/hello-client.js
Normal file
|
@ -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();
|
43
example/UDPSocket/rawBuffer/world.server.js
Normal file
43
example/UDPSocket/rawBuffer/world.server.js
Normal file
|
@ -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();
|
|
@ -1,10 +1,10 @@
|
||||||
var ipc=require('../../../node-ipc');
|
var ipc=require('../../../node-ipc');
|
||||||
|
|
||||||
/***************************************\
|
/***************************************\
|
||||||
*
|
*
|
||||||
* You should start both hello and world
|
* You should start both hello and world
|
||||||
* then you will see them communicating.
|
* then you will see them communicating.
|
||||||
*
|
*
|
||||||
* *************************************/
|
* *************************************/
|
||||||
|
|
||||||
ipc.config.id = 'hello';
|
ipc.config.id = 'hello';
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var net = require('net'),
|
var net = require('net'),
|
||||||
eventParser = require('../lib/eventParser.js'),
|
eventParser = require('../lib/eventParser.js'),
|
||||||
pubsub = require('event-pubsub');
|
pubsub = require('event-pubsub'),
|
||||||
|
Message = require('js-message');
|
||||||
|
|
||||||
function init(config,log){
|
function init(config,log){
|
||||||
var client={
|
var client={
|
||||||
|
@ -12,38 +13,36 @@ function init(config,log){
|
||||||
retriesRemaining:config.maxRetries||0
|
retriesRemaining:config.maxRetries||0
|
||||||
}
|
}
|
||||||
new pubsub(client);
|
new pubsub(client);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
function emit(type,data){
|
function emit(type,data){
|
||||||
this.log('dispatching event to '.debug, this.id.variable, this.path.variable,' : ', type.data,',', 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){
|
if(this.config.rawBuffer){
|
||||||
data=new Buffer(type,this.encoding);
|
message=new Buffer(type,this.encoding);
|
||||||
}else{
|
}else{
|
||||||
data=eventParser.format(
|
message=eventParser.format(message);
|
||||||
{
|
|
||||||
type:type,
|
|
||||||
data:data
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.socket.write(data);
|
this.socket.write(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
function connect(){
|
function connect(){
|
||||||
//init client object for scope persistance especially inside of socket events.
|
//init client object for scope persistance especially inside of socket events.
|
||||||
var client=this;
|
var client=this;
|
||||||
|
|
||||||
client.log('requested connection to '.debug, client.id.variable, client.path.variable);
|
client.log('requested connection to '.debug, client.id.variable, client.path.variable);
|
||||||
if(!this.path){
|
if(!this.path){
|
||||||
client.log('\n\n######\nerror: '.error, client.id .info,' client has not specified socket path it wishes to connect to.'.error);
|
client.log('\n\n######\nerror: '.error, client.id .info,' client has not specified socket path it wishes to connect to.'.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!client.port){
|
if(!client.port){
|
||||||
client.log('Connecting client on Unix Socket :'.debug, client.path.variable);
|
client.log('Connecting client on Unix Socket :'.debug, client.path.variable);
|
||||||
client.socket = net.connect(
|
client.socket = net.connect(
|
||||||
|
@ -60,16 +59,16 @@ function connect(){
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.socket.setEncoding(this.config.encoding);
|
client.socket.setEncoding(this.config.encoding);
|
||||||
|
|
||||||
client.socket.on(
|
client.socket.on(
|
||||||
'error',
|
'error',
|
||||||
function(err){
|
function(err){
|
||||||
client.log('\n\n######\nerror: '.error, err);
|
client.log('\n\n######\nerror: '.error, err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
client.socket.on(
|
client.socket.on(
|
||||||
'connect',
|
'connect',
|
||||||
function(){
|
function(){
|
||||||
|
@ -78,12 +77,12 @@ function connect(){
|
||||||
client.log('retrying reset')
|
client.log('retrying reset')
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
client.socket.on(
|
client.socket.on(
|
||||||
'close',
|
'close',
|
||||||
function(){
|
function(){
|
||||||
client.log('connection closed'.notice ,client.id.variable , client.path.variable, client.retriesRemaining+' tries remaining of '+client.config.maxRetries);
|
client.log('connection closed'.notice ,client.id.variable , client.path.variable, client.retriesRemaining+' tries remaining of '+client.config.maxRetries);
|
||||||
|
|
||||||
if(
|
if(
|
||||||
client.config.stopRetrying || client.retriesRemaining<1
|
client.config.stopRetrying || client.retriesRemaining<1
|
||||||
|
|
||||||
|
@ -93,15 +92,15 @@ function connect(){
|
||||||
'exceeded connection rety amount of'.warn,
|
'exceeded connection rety amount of'.warn,
|
||||||
" or stopRetrying flag set."
|
" or stopRetrying flag set."
|
||||||
);
|
);
|
||||||
|
|
||||||
client.socket.destroy();
|
client.socket.destroy();
|
||||||
client=undefined;
|
client=undefined;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.isRetrying=true;
|
client.isRetrying=true;
|
||||||
|
|
||||||
setTimeout(
|
setTimeout(
|
||||||
(
|
(
|
||||||
function(client){
|
function(client){
|
||||||
|
@ -114,18 +113,18 @@ function connect(){
|
||||||
if(!client.isRetrying)
|
if(!client.isRetrying)
|
||||||
client.retriesRemaining=client.config.maxRetries;
|
client.retriesRemaining=client.config.maxRetries;
|
||||||
},
|
},
|
||||||
100
|
100
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)(client),
|
)(client),
|
||||||
client.config.retry
|
client.config.retry
|
||||||
);
|
);
|
||||||
|
|
||||||
client.trigger('disconnect');
|
client.trigger('disconnect');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
client.socket.on(
|
client.socket.on(
|
||||||
'data',
|
'data',
|
||||||
function(data) {
|
function(data) {
|
||||||
|
@ -140,26 +139,26 @@ function connect(){
|
||||||
|
|
||||||
if(!this.ipcBuffer)
|
if(!this.ipcBuffer)
|
||||||
this.ipcBuffer='';
|
this.ipcBuffer='';
|
||||||
|
|
||||||
data=(this.ipcBuffer+=data);
|
data=(this.ipcBuffer+=data);
|
||||||
|
|
||||||
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
|
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);
|
client.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ipcBuffer='';
|
this.ipcBuffer='';
|
||||||
|
|
||||||
var events = eventParser.parse(data);
|
var events = eventParser.parse(data);
|
||||||
var eCount = events.length;
|
var eCount = events.length;
|
||||||
for(var i=0; i<eCount; i++){
|
for(var i=0; i<eCount; i++){
|
||||||
var e=JSON.parse(
|
var message=new Message;
|
||||||
events[i]
|
message.load(events[i]);
|
||||||
);
|
|
||||||
client.log('detected event of type '.debug, e.type.data, e.data);
|
client.log('detected event of type '.debug, message.type.data, message.data);
|
||||||
client.trigger(
|
client.trigger(
|
||||||
e.type,
|
message.type,
|
||||||
e.data
|
message.data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
function formatData(data){
|
var Message = require('js-message');
|
||||||
if(!data.data)
|
|
||||||
data.data={};
|
function formatData(message){
|
||||||
if(data.data['_maxListeners'])
|
if(!message.data){
|
||||||
delete data.data;
|
message.data={};
|
||||||
|
}
|
||||||
data=JSON.stringify(data)+parser.delimiter;
|
if(message.data['_maxListeners']){
|
||||||
return data;
|
message.data={};
|
||||||
|
}
|
||||||
|
|
||||||
|
message=message.JSON+parser.delimiter;
|
||||||
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseDataEvents(data){
|
function parseDataEvents(data){
|
||||||
|
@ -20,4 +24,4 @@ var parser={
|
||||||
delimiter : '\f'
|
delimiter : '\f'
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports=parser;
|
module.exports=parser;
|
||||||
|
|
|
@ -2,70 +2,59 @@ var net = require('net'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
dgram = require('dgram'),
|
dgram = require('dgram'),
|
||||||
eventParser = require('../lib/eventParser.js'),
|
eventParser = require('../lib/eventParser.js'),
|
||||||
pubsub = require('event-pubsub');
|
pubsub = require('event-pubsub'),
|
||||||
|
Message = require('js-message');
|
||||||
|
|
||||||
function emit(socket, type, data){
|
function emit(socket, type, data){
|
||||||
if(!data)
|
|
||||||
data=false;
|
|
||||||
this.log('dispatching event to socket'.debug, ' : ', type.data, data);
|
this.log('dispatching event to socket'.debug, ' : ', type.data, data);
|
||||||
|
|
||||||
var event={
|
var message=new Message;
|
||||||
type:type,
|
message.type=type;
|
||||||
data:data
|
message.data=data;
|
||||||
}
|
|
||||||
|
|
||||||
if(this.config.rawBuffer){
|
if(this.config.rawBuffer){
|
||||||
data=new Buffer(type,this.encoding);
|
message=new Buffer(type,this.encoding);
|
||||||
}else{
|
}else{
|
||||||
data=eventParser.format(
|
message=eventParser.format(message);
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.udp4 || this.udp6){
|
if(this.udp4 || this.udp6){
|
||||||
|
|
||||||
if(!socket.address || !socket.port){
|
if(!socket.address || !socket.port){
|
||||||
this.log('Attempting to emit to a single UDP socket without supplying socket address or port. Redispatching event as broadcast to all connected sockets');
|
this.log('Attempting to emit to a single UDP socket without supplying socket address or port. Redispatching event as broadcast to all connected sockets');
|
||||||
this.broadcast(type,data);
|
this.broadcast(type,data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server.write(
|
this.server.write(
|
||||||
data,
|
message,
|
||||||
socket
|
socket
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.write(data);
|
socket.write(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
function broadcast(type,data){
|
function broadcast(type,data){
|
||||||
this.log('broadcasting event to all known sockets listening to '.debug, this.path.variable,' : ', ((this.port)?this.port:''), type, data);
|
this.log('broadcasting event to all known sockets listening to '.debug, this.path.variable,' : ', ((this.port)?this.port:''), type, data);
|
||||||
if(!data)
|
var message=new Message;
|
||||||
data=false;
|
message.type=type;
|
||||||
|
message.data=data;
|
||||||
var event={
|
|
||||||
type:type,
|
|
||||||
data:data
|
|
||||||
};
|
|
||||||
|
|
||||||
if(this.config.rawBuffer){
|
if(this.config.rawBuffer){
|
||||||
data=new Buffer(type,this.encoding);
|
message=new Buffer(type,this.encoding);
|
||||||
}else{
|
}else{
|
||||||
data=eventParser.format(
|
message=eventParser.format(message);
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(this.udp4 || this.udp6){
|
if(this.udp4 || this.udp6){
|
||||||
for(var i=1, count=this.sockets.length; i<count; i++){
|
for(var i=1, count=this.sockets.length; i<count; i++){
|
||||||
this.server.write(data,this.sockets[i]);
|
this.server.write(message,this.sockets[i]);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
for(var i=0, count=this.sockets.length; i<count; i++){
|
for(var i=0, count=this.sockets.length; i<count; i++){
|
||||||
this.sockets[i].write(data);
|
this.sockets[i].write(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -89,7 +78,7 @@ function init(path,config,log,port){
|
||||||
},
|
},
|
||||||
broadcast : {
|
broadcast : {
|
||||||
'events.broadcasting' : 'data.events is a JSON object of event definitions by type '+config.id+' will broadcast on '+path,
|
'events.broadcasting' : 'data.events is a JSON object of event definitions by type '+config.id+' will broadcast on '+path,
|
||||||
'events.listening' : 'data.events is a JSON object of event definitions by type '+config.id+' is listening for on '+path
|
'events.listening' : 'data.events is a JSON object of event definitions by type '+config.id+' is listening for on '+path
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onStart : function(socket){
|
onStart : function(socket){
|
||||||
|
@ -103,14 +92,14 @@ function init(path,config,log,port){
|
||||||
server.log('Socket Server Path not specified, refusing to start'.warn);
|
server.log('Socket Server Path not specified, refusing to start'.warn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.unlink(
|
fs.unlink(
|
||||||
this.path,
|
this.path,
|
||||||
(
|
(
|
||||||
function(server){
|
function(server){
|
||||||
return function () {
|
return function () {
|
||||||
server.log('starting server on '.debug,server.path.variable,((server.port)?':'+server.port:'').variable);
|
server.log('starting server on '.debug,server.path.variable,((server.port)?':'+server.port:'').variable);
|
||||||
|
|
||||||
if(!server.udp4 && !server.udp6){
|
if(!server.udp4 && !server.udp6){
|
||||||
server.server=net.createServer(
|
server.server=net.createServer(
|
||||||
serverCreated
|
serverCreated
|
||||||
|
@ -119,15 +108,15 @@ function init(path,config,log,port){
|
||||||
function UDPWrite(message,socket){
|
function UDPWrite(message,socket){
|
||||||
var data=new Buffer(message, server.config.encoding);
|
var data=new Buffer(message, server.config.encoding);
|
||||||
server.server.send(
|
server.server.send(
|
||||||
data,
|
data,
|
||||||
0,
|
0,
|
||||||
data.length,
|
data.length,
|
||||||
socket.port,
|
socket.port,
|
||||||
socket.address,
|
socket.address,
|
||||||
function(err, bytes) {
|
function(err, bytes) {
|
||||||
if(err){
|
if(err){
|
||||||
server.trigger(
|
server.trigger(
|
||||||
'error',
|
'error',
|
||||||
function(err){
|
function(err){
|
||||||
server.trigger('error',err);
|
server.trigger('error',err);
|
||||||
}
|
}
|
||||||
|
@ -136,25 +125,25 @@ function init(path,config,log,port){
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.server=dgram.createSocket(
|
server.server=dgram.createSocket(
|
||||||
((server.udp4)? 'udp4':'udp6')
|
((server.udp4)? 'udp4':'udp6')
|
||||||
);
|
);
|
||||||
server.server.write=UDPWrite;
|
server.server.write=UDPWrite;
|
||||||
server.server.on(
|
server.server.on(
|
||||||
'listening',
|
'listening',
|
||||||
function () {
|
function () {
|
||||||
serverCreated(server.server)
|
serverCreated(server.server)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serverCreated(socket) {
|
function serverCreated(socket) {
|
||||||
server.sockets.push(socket);
|
server.sockets.push(socket);
|
||||||
|
|
||||||
if(socket.setEncoding)
|
if(socket.setEncoding)
|
||||||
socket.setEncoding(server.config.encoding);
|
socket.setEncoding(server.config.encoding);
|
||||||
|
|
||||||
server.log('## socket connection to server detected ##'.rainbow);
|
server.log('## socket connection to server detected ##'.rainbow);
|
||||||
socket.on(
|
socket.on(
|
||||||
'close',
|
'close',
|
||||||
|
@ -165,14 +154,14 @@ function init(path,config,log,port){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
'error',
|
'error',
|
||||||
function(err){
|
function(err){
|
||||||
server.trigger('error',err);
|
server.trigger('error',err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
'data',
|
'data',
|
||||||
function(data,UDPSocket){
|
function(data,UDPSocket){
|
||||||
|
@ -191,32 +180,34 @@ function init(path,config,log,port){
|
||||||
this.ipcBuffer='';
|
this.ipcBuffer='';
|
||||||
|
|
||||||
data=(this.ipcBuffer+=data);
|
data=(this.ipcBuffer+=data);
|
||||||
|
|
||||||
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
|
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
|
||||||
server.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice);
|
server.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ipcBuffer='';
|
this.ipcBuffer='';
|
||||||
|
|
||||||
data=eventParser.parse(data);
|
data=eventParser.parse(data);
|
||||||
|
|
||||||
while(data.length>0){
|
while(data.length>0){
|
||||||
var e=JSON.parse(data.shift());
|
var message=new Message;
|
||||||
server.log('received event of : '.debug,e.type.data,e.data);
|
message.load(data.shift());
|
||||||
|
|
||||||
if(e.data.id)
|
server.log('received event of : '.debug,message.type.data,message.data);
|
||||||
sock.id=e.data.id;
|
|
||||||
|
if(message.data.id)
|
||||||
|
sock.id=message.data.id;
|
||||||
|
|
||||||
server.trigger(
|
server.trigger(
|
||||||
e.type,
|
message.type,
|
||||||
e.data,
|
message.data,
|
||||||
sock
|
sock
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
socket.on(
|
socket.on(
|
||||||
'message',
|
'message',
|
||||||
function(msg,rinfo) {
|
function(msg,rinfo) {
|
||||||
|
@ -233,12 +224,12 @@ function init(path,config,log,port){
|
||||||
socket.emit('data',data,rinfo);
|
socket.emit('data',data,rinfo);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
server.trigger(
|
server.trigger(
|
||||||
'connect',
|
'connect',
|
||||||
socket
|
socket
|
||||||
);
|
);
|
||||||
|
|
||||||
if(server.config.rawBuffer){
|
if(server.config.rawBuffer){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -247,28 +238,28 @@ function init(path,config,log,port){
|
||||||
'get.events.broadcasting',
|
'get.events.broadcasting',
|
||||||
socket
|
socket
|
||||||
);
|
);
|
||||||
|
|
||||||
server.trigger(
|
server.trigger(
|
||||||
'get.events.listening',
|
'get.events.listening',
|
||||||
socket
|
socket
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function started(socket){
|
function started(socket){
|
||||||
server.onStart(socket)
|
server.onStart(socket)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!port){
|
if(!port){
|
||||||
server.log('starting server as'.debug, 'Unix Socket'.variable);
|
server.log('starting server as'.debug, 'Unix Socket'.variable);
|
||||||
server.server.listen(
|
server.server.listen(
|
||||||
server.path,
|
server.path,
|
||||||
started
|
started
|
||||||
);
|
);
|
||||||
|
|
||||||
server.server.maxConnections=server.maxConnections;
|
server.server.maxConnections=server.maxConnections;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!server.udp4 && !server.udp4){
|
if(!server.udp4 && !server.udp4){
|
||||||
server.log('starting server as'.debug, 'TCP'.variable);
|
server.log('starting server as'.debug, 'TCP'.variable);
|
||||||
server.server.listen(
|
server.server.listen(
|
||||||
|
@ -278,13 +269,13 @@ function init(path,config,log,port){
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable);
|
server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable);
|
||||||
server.server.bind(
|
server.server.bind(
|
||||||
server.port,
|
server.port,
|
||||||
server.path
|
server.path
|
||||||
);
|
);
|
||||||
|
|
||||||
started(
|
started(
|
||||||
{
|
{
|
||||||
address : server.path,
|
address : server.path,
|
||||||
|
@ -297,9 +288,9 @@ function init(path,config,log,port){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new pubsub(server);
|
new pubsub(server);
|
||||||
|
|
||||||
server.on(
|
server.on(
|
||||||
'get.events.broadcasting',
|
'get.events.broadcasting',
|
||||||
function(socket){
|
function(socket){
|
||||||
|
@ -313,7 +304,7 @@ function init(path,config,log,port){
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
server.on(
|
server.on(
|
||||||
'get.events.listening',
|
'get.events.listening',
|
||||||
function(socket){
|
function(socket){
|
||||||
|
@ -326,35 +317,35 @@ function init(path,config,log,port){
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
server.on(
|
server.on(
|
||||||
'close',
|
'close',
|
||||||
function(){
|
function(){
|
||||||
for(var i=0, count=server.sockets.length; i<count; i++){
|
for(var i=0, count=server.sockets.length; i<count; i++){
|
||||||
var socket=server.sockets[i];
|
var socket=server.sockets[i];
|
||||||
var destroyedSocketId=false;
|
var destroyedSocketId=false;
|
||||||
|
|
||||||
if(socket){
|
if(socket){
|
||||||
if(socket.readable)
|
if(socket.readable)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(socket.id)
|
if(socket.id)
|
||||||
destroyedSocketId=socket.id;
|
destroyedSocketId=socket.id;
|
||||||
|
|
||||||
server.log('socket disconnected'.notice,' '+destroyedSocketId.variable);
|
server.log('socket disconnected'.notice,' '+destroyedSocketId.variable);
|
||||||
|
|
||||||
if(socket)
|
if(socket)
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
|
|
||||||
server.sockets.splice(i,1);
|
server.sockets.splice(i,1);
|
||||||
|
|
||||||
server.trigger('socket.disconnected', socket, destroyedSocketId);
|
server.trigger('socket.disconnected', socket, destroyedSocketId);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
|
|
4
node_modules/colors/package.json
generated
vendored
4
node_modules/colors/package.json
generated
vendored
|
@ -16,7 +16,7 @@
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/Marak/colors.js.git"
|
"url": "git+ssh://git@github.com/Marak/colors.js.git"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.1.90"
|
"node": ">=0.1.90"
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
"shasum": "2423fe6678ac0c5dae8852e5d0e5be08c997abcc",
|
"shasum": "2423fe6678ac0c5dae8852e5d0e5be08c997abcc",
|
||||||
"tarball": "http://registry.npmjs.org/colors/-/colors-0.6.2.tgz"
|
"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",
|
"_npmVersion": "1.2.30",
|
||||||
"_npmUser": {
|
"_npmUser": {
|
||||||
"name": "marak",
|
"name": "marak",
|
||||||
|
|
4
node_modules/event-pubsub/package.json
generated
vendored
4
node_modules/event-pubsub/package.json
generated
vendored
|
@ -11,7 +11,7 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RIAEvangelist/event-pubsub.git"
|
"url": "git+https://github.com/RIAEvangelist/event-pubsub.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"event",
|
"event",
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
"shasum": "c81c49b101cdb4892d8fa2631b443184db2de6aa",
|
"shasum": "c81c49b101cdb4892d8fa2631b443184db2de6aa",
|
||||||
"tarball": "http://registry.npmjs.org/event-pubsub/-/event-pubsub-1.0.3.tgz"
|
"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",
|
"_npmVersion": "1.4.3",
|
||||||
"_npmUser": {
|
"_npmUser": {
|
||||||
"name": "riaevangelist",
|
"name": "riaevangelist",
|
||||||
|
|
23
node_modules/node-cmd/package.json
generated
vendored
23
node_modules/node-cmd/package.json
generated
vendored
|
@ -11,7 +11,7 @@
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RIAEvangelist/node-cmd.git"
|
"url": "git+https://github.com/RIAEvangelist/node-cmd.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"commandline",
|
"commandline",
|
||||||
|
@ -29,10 +29,25 @@
|
||||||
"url": "https://github.com/RIAEvangelist/node-cmd/issues"
|
"url": "https://github.com/RIAEvangelist/node-cmd/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/RIAEvangelist/node-cmd",
|
"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",
|
"gitHead": "a003426996e8594af31a6486cfb7d28d0a547bc9",
|
||||||
"_id": "node-cmd@1.0.2",
|
"_id": "node-cmd@1.0.2",
|
||||||
"_shasum": "89cdb50181476cdd127763d5c8514499fe3c038d",
|
"_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!"
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,12 @@
|
||||||
"example": "example"
|
"example": "example"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"event-pubsub": "~1.0.3",
|
|
||||||
"colors": "~0.6.2",
|
"colors": "~0.6.2",
|
||||||
|
"event-pubsub": "~1.0.3",
|
||||||
|
"js-message": "*",
|
||||||
"node-cmd": "~1.0.1"
|
"node-cmd": "~1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {},
|
||||||
"colors": "*",
|
|
||||||
"event-pubsub": "*",
|
|
||||||
"node-cmd": "*"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue