First Commit of new way of building the Platform
This commit is contained in:
1 parent
e48cf0dae5
commit
40e60b42cc
4616 files changed
+713402
No files matched your search
+257
@@ -0,0 +1,257 @@
|
||||
'use strict';
|
||||
|
||||
const net = require('net'),
|
||||
tls = require('tls'),
|
||||
EventParser = require('../entities/EventParser.js'),
|
||||
Message = require('js-message'),
|
||||
fs = require('fs'),
|
||||
Queue = require('js-queue');
|
||||
|
||||
let Events = require('event-pubsub/es5');
|
||||
if(process.version[1]>4){
|
||||
Events = require('event-pubsub');
|
||||
}
|
||||
|
||||
let eventParser = new EventParser();
|
||||
|
||||
class Client extends Events{
|
||||
constructor(config,log){
|
||||
super();
|
||||
Object.assign(
|
||||
this,
|
||||
{
|
||||
Client : Client,
|
||||
config : config,
|
||||
queue : new Queue,
|
||||
socket : false,
|
||||
connect : connect,
|
||||
emit : emit,
|
||||
log : log,
|
||||
retriesRemaining:config.maxRetries||0,
|
||||
explicitlyDisconnected: false
|
||||
}
|
||||
);
|
||||
|
||||
eventParser=new EventParser(this.config);
|
||||
}
|
||||
}
|
||||
|
||||
function emit(type,data){
|
||||
this.log('dispatching event to ', this.id, this.path, ' : ', type, ',', data);
|
||||
|
||||
let message=new Message;
|
||||
message.type=type;
|
||||
message.data=data;
|
||||
|
||||
if(this.config.rawBuffer){
|
||||
message=new Buffer(type,this.config.encoding);
|
||||
}else{
|
||||
message=eventParser.format(message);
|
||||
}
|
||||
|
||||
if(!this.config.sync){
|
||||
this.socket.write(message);
|
||||
return;
|
||||
}
|
||||
|
||||
this.queue.add(
|
||||
syncEmit.bind(this,message)
|
||||
);
|
||||
}
|
||||
|
||||
function syncEmit(message){
|
||||
this.log('dispatching event to ', this.id, this.path, ' : ', message);
|
||||
this.socket.write(message);
|
||||
}
|
||||
|
||||
function connect(){
|
||||
//init client object for scope persistance especially inside of socket events.
|
||||
let client=this;
|
||||
|
||||
client.log('requested connection to ', client.id, client.path);
|
||||
if(!this.path){
|
||||
client.log('\n\n######\nerror: ', client.id ,' client has not specified socket path it wishes to connect to.');
|
||||
return;
|
||||
}
|
||||
|
||||
const options={};
|
||||
|
||||
if(!client.port){
|
||||
client.log('Connecting client on Unix Socket :', client.path);
|
||||
|
||||
options.path=client.path;
|
||||
|
||||
if (process.platform ==='win32' && !client.path.startsWith('\\\\.\\pipe\\')){
|
||||
options.path = options.path.replace(/^\//, '');
|
||||
options.path = options.path.replace(/\//g, '-');
|
||||
options.path= `\\\\.\\pipe\\${options.path}`;
|
||||
}
|
||||
|
||||
client.socket = net.connect(options);
|
||||
}else{
|
||||
options.host=client.path;
|
||||
options.port=client.port;
|
||||
|
||||
if(client.config.interface.localAddress){
|
||||
options.localAddress=client.config.interface.localAddress;
|
||||
}
|
||||
|
||||
if(client.config.interface.localPort){
|
||||
options.localPort=client.config.interface.localPort;
|
||||
}
|
||||
|
||||
if(client.config.interface.family){
|
||||
options.family=client.config.interface.family;
|
||||
}
|
||||
|
||||
if(client.config.interface.hints){
|
||||
options.hints=client.config.interface.hints;
|
||||
}
|
||||
|
||||
if(client.config.interface.lookup){
|
||||
options.lookup=client.config.interface.lookup;
|
||||
}
|
||||
|
||||
if(!client.config.tls){
|
||||
client.log('Connecting client via TCP to', options);
|
||||
client.socket = net.connect(options);
|
||||
}else{
|
||||
client.log('Connecting client via TLS to', client.path ,client.port,client.config.tls);
|
||||
if(client.config.tls.private){
|
||||
client.config.tls.key=fs.readFileSync(client.config.tls.private);
|
||||
}
|
||||
if(client.config.tls.public){
|
||||
client.config.tls.cert=fs.readFileSync(client.config.tls.public);
|
||||
}
|
||||
if(client.config.tls.trustedConnections){
|
||||
if(typeof client.config.tls.trustedConnections === 'string'){
|
||||
client.config.tls.trustedConnections=[client.config.tls.trustedConnections];
|
||||
}
|
||||
client.config.tls.ca=[];
|
||||
for(let i=0; i<client.config.tls.trustedConnections.length; i++){
|
||||
client.config.tls.ca.push(
|
||||
fs.readFileSync(client.config.tls.trustedConnections[i])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(client.config.tls,options);
|
||||
|
||||
client.socket = tls.connect(
|
||||
client.config.tls
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
client.socket.setEncoding(this.config.encoding);
|
||||
|
||||
client.socket.on(
|
||||
'error',
|
||||
function(err){
|
||||
client.log('\n\n######\nerror: ', err);
|
||||
client.publish('error', err);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
client.socket.on(
|
||||
'connect',
|
||||
function connectionMade(){
|
||||
client.publish('connect');
|
||||
client.retriesRemaining=client.config.maxRetries;
|
||||
client.log('retrying reset');
|
||||
}
|
||||
);
|
||||
|
||||
client.socket.on(
|
||||
'close',
|
||||
function connectionClosed(){
|
||||
client.log('connection closed' ,client.id , client.path,
|
||||
client.retriesRemaining, 'tries remaining of', client.config.maxRetries
|
||||
);
|
||||
|
||||
if(
|
||||
client.config.stopRetrying ||
|
||||
client.retriesRemaining<1 ||
|
||||
client.explicitlyDisconnected
|
||||
|
||||
){
|
||||
client.publish('disconnect');
|
||||
client.log(
|
||||
(client.config.id),
|
||||
'exceeded connection rety amount of',
|
||||
' or stopRetrying flag set.'
|
||||
);
|
||||
|
||||
client.socket.destroy();
|
||||
client.publish('destroy');
|
||||
client=undefined;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(
|
||||
function retryTimeout(){
|
||||
client.retriesRemaining--;
|
||||
client.connect();
|
||||
}.bind(null,client),
|
||||
client.config.retry
|
||||
);
|
||||
|
||||
client.publish('disconnect');
|
||||
}
|
||||
);
|
||||
|
||||
client.socket.on(
|
||||
'data',
|
||||
function(data) {
|
||||
client.log('## received events ##');
|
||||
if(client.config.rawBuffer){
|
||||
client.publish(
|
||||
'data',
|
||||
new Buffer(data,client.config.encoding)
|
||||
);
|
||||
if(!client.config.sync){
|
||||
return;
|
||||
}
|
||||
|
||||
client.queue.next();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.ipcBuffer){
|
||||
this.ipcBuffer='';
|
||||
}
|
||||
|
||||
data=(this.ipcBuffer+=data);
|
||||
|
||||
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
|
||||
client.log('Messages are large, You may want to consider smaller messages.');
|
||||
return;
|
||||
}
|
||||
|
||||
this.ipcBuffer='';
|
||||
|
||||
const events = eventParser.parse(data);
|
||||
const eCount = events.length;
|
||||
for(let i=0; i<eCount; i++){
|
||||
let message=new Message;
|
||||
message.load(events[i]);
|
||||
|
||||
client.log('detected event', message.type, message.data);
|
||||
client.publish(
|
||||
message.type,
|
||||
message.data
|
||||
);
|
||||
}
|
||||
|
||||
if(!client.config.sync){
|
||||
return;
|
||||
}
|
||||
|
||||
client.queue.next();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports=Client;
|
||||
+402
@@ -0,0 +1,402 @@
|
||||
'use strict';
|
||||
|
||||
const net = require('net'),
|
||||
tls = require('tls'),
|
||||
fs = require('fs'),
|
||||
dgram = require('dgram'),
|
||||
EventParser = require('../entities/EventParser.js'),
|
||||
Message = require('js-message');
|
||||
|
||||
let Events = require('event-pubsub/es5');
|
||||
if(process.version[1]>4){
|
||||
Events = require('event-pubsub');
|
||||
}
|
||||
|
||||
let eventParser = new EventParser();
|
||||
|
||||
class Server extends Events{
|
||||
constructor(path,config,log,port){
|
||||
super();
|
||||
Object.assign(
|
||||
this,
|
||||
{
|
||||
config : config,
|
||||
path : path,
|
||||
port : port,
|
||||
udp4 : false,
|
||||
udp6 : false,
|
||||
log : log,
|
||||
server : false,
|
||||
sockets : [],
|
||||
emit : emit,
|
||||
broadcast : broadcast
|
||||
}
|
||||
);
|
||||
|
||||
eventParser=new EventParser(this.config);
|
||||
|
||||
this.on(
|
||||
'close',
|
||||
serverClosed.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
onStart(socket){
|
||||
this.trigger(
|
||||
'start',
|
||||
socket
|
||||
);
|
||||
}
|
||||
|
||||
stop(){
|
||||
this.server.close();
|
||||
}
|
||||
|
||||
start(){
|
||||
if(!this.path){
|
||||
this.log('Socket Server Path not specified, refusing to start');
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.config.unlink){
|
||||
fs.unlink(
|
||||
this.path,
|
||||
startServer.bind(this)
|
||||
);
|
||||
}else{
|
||||
startServer.bind(this)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emit(socket, type, data){
|
||||
this.log('dispatching event to socket', ' : ', type, data);
|
||||
|
||||
let message=new Message;
|
||||
message.type=type;
|
||||
message.data=data;
|
||||
|
||||
if(this.config.rawBuffer){
|
||||
this.log(this.config.encoding)
|
||||
message=new Buffer(type,this.config.encoding);
|
||||
}else{
|
||||
message=eventParser.format(message);
|
||||
}
|
||||
|
||||
if(this.udp4 || this.udp6){
|
||||
|
||||
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.broadcast(type,data);
|
||||
return;
|
||||
}
|
||||
|
||||
this.server.write(
|
||||
message,
|
||||
socket
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
socket.write(message);
|
||||
}
|
||||
|
||||
function broadcast(type,data){
|
||||
this.log('broadcasting event to all known sockets listening to ', this.path,' : ', ((this.port)?this.port:''), type, data);
|
||||
let message=new Message;
|
||||
message.type=type;
|
||||
message.data=data;
|
||||
|
||||
if(this.config.rawBuffer){
|
||||
message=new Buffer(type,this.config.encoding);
|
||||
}else{
|
||||
message=eventParser.format(message);
|
||||
}
|
||||
|
||||
if(this.udp4 || this.udp6){
|
||||
for(let i=1, count=this.sockets.length; i<count; i++){
|
||||
this.server.write(message,this.sockets[i]);
|
||||
}
|
||||
}else{
|
||||
for(let i=0, count=this.sockets.length; i<count; i++){
|
||||
this.sockets[i].write(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function serverClosed(){
|
||||
for(let i=0, count=this.sockets.length; i<count; i++){
|
||||
let socket=this.sockets[i];
|
||||
let destroyedSocketId=false;
|
||||
|
||||
if(socket){
|
||||
if(socket.readable){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(socket.id){
|
||||
destroyedSocketId=socket.id;
|
||||
}
|
||||
|
||||
this.log('socket disconnected',destroyedSocketId.toString());
|
||||
|
||||
if(socket && socket.destroy){
|
||||
socket.destroy();
|
||||
}
|
||||
|
||||
this.sockets.splice(i,1);
|
||||
|
||||
this.publish('socket.disconnected', socket, destroyedSocketId);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function gotData(socket,data,UDPSocket){
|
||||
let sock=((this.udp4 || this.udp6)? UDPSocket : socket);
|
||||
if(this.config.rawBuffer){
|
||||
data=new Buffer(data,this.config.encoding);
|
||||
this.publish(
|
||||
'data',
|
||||
data,
|
||||
sock
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.ipcBuffer){
|
||||
this.ipcBuffer='';
|
||||
}
|
||||
|
||||
data=(this.ipcBuffer+=data);
|
||||
|
||||
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
|
||||
this.log('Messages are large, You may want to consider smaller messages.');
|
||||
return;
|
||||
}
|
||||
|
||||
this.ipcBuffer='';
|
||||
|
||||
data=eventParser.parse(data);
|
||||
|
||||
while(data.length>0){
|
||||
let message=new Message;
|
||||
message.load(data.shift());
|
||||
|
||||
// Only set the sock id if it is specified.
|
||||
if (message.data && message.data.id){
|
||||
sock.id=message.data.id;
|
||||
}
|
||||
|
||||
this.log('received event of : ',message.type,message.data);
|
||||
|
||||
this.publish(
|
||||
message.type,
|
||||
message.data,
|
||||
sock
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function socketClosed(socket){
|
||||
this.publish(
|
||||
'close',
|
||||
socket
|
||||
);
|
||||
}
|
||||
|
||||
function serverCreated(socket) {
|
||||
this.sockets.push(socket);
|
||||
|
||||
if(socket.setEncoding){
|
||||
socket.setEncoding(this.config.encoding);
|
||||
}
|
||||
|
||||
this.log('## socket connection to server detected ##');
|
||||
socket.on(
|
||||
'close',
|
||||
socketClosed.bind(this)
|
||||
);
|
||||
|
||||
socket.on(
|
||||
'error',
|
||||
function(err){
|
||||
this.log('server socket error',err);
|
||||
|
||||
this.publish('error',err);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
socket.on(
|
||||
'data',
|
||||
gotData.bind(this,socket)
|
||||
);
|
||||
|
||||
socket.on(
|
||||
'message',
|
||||
function(msg,rinfo) {
|
||||
if (!rinfo){
|
||||
return;
|
||||
}
|
||||
|
||||
this.log('Received UDP message from ', rinfo.address, rinfo.port);
|
||||
let data;
|
||||
|
||||
if(this.config.rawSocket){
|
||||
data=new Buffer(msg,this.config.encoding);
|
||||
}else{
|
||||
data=msg.toString();
|
||||
}
|
||||
socket.emit('data',data,rinfo);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.publish(
|
||||
'connect',
|
||||
socket
|
||||
);
|
||||
|
||||
if(this.config.rawBuffer){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function startServer() {
|
||||
this.log(
|
||||
'starting server on ',this.path,
|
||||
((this.port)?`:${this.port}`:'')
|
||||
);
|
||||
|
||||
if(!this.udp4 && !this.udp6){
|
||||
this.log('starting TLS server',this.config.tls);
|
||||
if(!this.config.tls){
|
||||
this.server=net.createServer(
|
||||
serverCreated.bind(this)
|
||||
);
|
||||
}else{
|
||||
startTLSServer.bind(this)();
|
||||
}
|
||||
}else{
|
||||
this.server=dgram.createSocket(
|
||||
((this.udp4)? 'udp4':'udp6')
|
||||
);
|
||||
this.server.write=UDPWrite.bind(this);
|
||||
this.server.on(
|
||||
'listening',
|
||||
function UDPServerStarted() {
|
||||
serverCreated.bind(this)(this.server);
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
this.server.on(
|
||||
'error',
|
||||
function(err){
|
||||
this.log('server error',err);
|
||||
|
||||
this.publish(
|
||||
'error',
|
||||
err
|
||||
);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.server.maxConnections=this.config.maxConnections;
|
||||
|
||||
if(!this.port){
|
||||
this.log('starting server as', 'Unix || Windows Socket');
|
||||
if (process.platform ==='win32'){
|
||||
this.path = this.path.replace(/^\//, '');
|
||||
this.path = this.path.replace(/\//g, '-');
|
||||
this.path= `\\\\.\\pipe\\${this.path}`;
|
||||
}
|
||||
|
||||
this.server.listen(
|
||||
this.path,
|
||||
this.onStart.bind(this)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.udp4 && !this.udp6){
|
||||
this.log('starting server as', (this.config.tls?'TLS':'TCP'));
|
||||
this.server.listen(
|
||||
this.port,
|
||||
this.path,
|
||||
this.onStart.bind(this)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log('starting server as',((this.udp4)? 'udp4':'udp6'));
|
||||
|
||||
this.server.bind(
|
||||
this.port,
|
||||
this.path
|
||||
);
|
||||
|
||||
this.onStart(
|
||||
{
|
||||
address : this.path,
|
||||
port : this.port
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function startTLSServer(){
|
||||
this.log('starting TLS server',this.config.tls);
|
||||
if(this.config.tls.private){
|
||||
this.config.tls.key=fs.readFileSync(this.config.tls.private);
|
||||
}else{
|
||||
this.config.tls.key=fs.readFileSync(`${__dirname}/../local-node-ipc-certs/private/server.key`);
|
||||
}
|
||||
if(this.config.tls.public){
|
||||
this.config.tls.cert=fs.readFileSync(this.config.tls.public);
|
||||
}else{
|
||||
this.config.tls.cert=fs.readFileSync(`${__dirname}/../local-node-ipc-certs/server.pub`);
|
||||
}
|
||||
if(this.config.tls.dhparam){
|
||||
this.config.tls.dhparam=fs.readFileSync(this.config.tls.dhparam);
|
||||
}
|
||||
if(this.config.tls.trustedConnections){
|
||||
if(typeof this.config.tls.trustedConnections === 'string'){
|
||||
this.config.tls.trustedConnections=[this.config.tls.trustedConnections];
|
||||
}
|
||||
this.config.tls.ca=[];
|
||||
for(let i=0; i<this.config.tls.trustedConnections.length; i++){
|
||||
this.config.tls.ca.push(
|
||||
fs.readFileSync(this.config.tls.trustedConnections[i])
|
||||
);
|
||||
}
|
||||
}
|
||||
this.server=tls.createServer(
|
||||
this.config.tls,
|
||||
serverCreated.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
function UDPWrite(message,socket){
|
||||
let data=new Buffer(message, this.config.encoding);
|
||||
this.server.send(
|
||||
data,
|
||||
0,
|
||||
data.length,
|
||||
socket.port,
|
||||
socket.address,
|
||||
function(err, bytes) {
|
||||
if(err){
|
||||
this.log('error writing data to socket',err);
|
||||
this.publish(
|
||||
'error',
|
||||
function(err){
|
||||
this.publish('error',err);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports=Server;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
/*eslint no-magic-numbers: ["error", { "ignore": [ 0] }]*/
|
||||
|
||||
/**
|
||||
* @module entities
|
||||
*/
|
||||
|
||||
const os = require('os');
|
||||
|
||||
/**
|
||||
* @class Defaults
|
||||
* @description Defaults Entity
|
||||
*/
|
||||
class Defaults{
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @method constructor
|
||||
* @return {void}
|
||||
*/
|
||||
constructor(){
|
||||
|
||||
this.appspace='app.';
|
||||
this.socketRoot='/tmp/';
|
||||
this.id=os.hostname();
|
||||
|
||||
this.encoding='utf8';
|
||||
this.rawBuffer=false;
|
||||
this.sync=false;
|
||||
this.unlink=true;
|
||||
|
||||
this.delimiter='\f';
|
||||
|
||||
this.silent=false;
|
||||
this.logDepth=5;
|
||||
this.logInColor=true;
|
||||
this.logger=console.log.bind(console);
|
||||
|
||||
this.maxConnections=100;
|
||||
this.retry=500;
|
||||
this.maxRetries=Infinity;
|
||||
this.stopRetrying=false;
|
||||
|
||||
this.IPType=getIPType();
|
||||
this.tls=false;
|
||||
this.networkHost = (this.IPType == 'IPv6') ? '::1' : '127.0.0.1';
|
||||
this.networkPort = 8000;
|
||||
|
||||
this.interface={
|
||||
localAddress:false,
|
||||
localPort:false,
|
||||
family:false,
|
||||
hints:false,
|
||||
lookup:false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* method to get ip type
|
||||
*
|
||||
* @method getIPType
|
||||
* @return {string} ip type
|
||||
*/
|
||||
function getIPType() {
|
||||
const networkInterfaces = os.networkInterfaces();
|
||||
let IPType = '';
|
||||
if (networkInterfaces
|
||||
&& Array.isArray(networkInterfaces)
|
||||
&& networkInterfaces.length > 0) {
|
||||
// getting the family of first network interface available
|
||||
IPType = networkInterfaces [
|
||||
Object.keys( networkInterfaces )[0]
|
||||
][0].family;
|
||||
}
|
||||
return IPType;
|
||||
}
|
||||
|
||||
module.exports=Defaults;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const Defaults = require('./Defaults.js');
|
||||
|
||||
class Parser{
|
||||
constructor(config){
|
||||
if(!config){
|
||||
config=new Defaults;
|
||||
}
|
||||
this.delimiter=config.delimiter;
|
||||
}
|
||||
|
||||
format(message){
|
||||
if(!message.data && message.data!==false && message.data!==0){
|
||||
message.data={};
|
||||
}
|
||||
if(message.data['_maxListeners']){
|
||||
message.data={};
|
||||
}
|
||||
|
||||
message=message.JSON+this.delimiter;
|
||||
return message;
|
||||
}
|
||||
|
||||
parse(data){
|
||||
let events=data.split(this.delimiter);
|
||||
events.pop();
|
||||
return events;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports=Parser;
|
||||
Generated
Vendored
+44
@@ -0,0 +1,44 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
ipc.config.maxRetries= 10;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'goodbye'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
const 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.maxRetries=10;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
const 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;
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from', (data.id), (data.message));
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection');
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
id:ipc.config.id
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
const 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.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
const 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.maxConnections=1;
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log('DISCONNECTED\n\n',arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'error',
|
||||
function(err){
|
||||
ipc.log('Got an ERROR!',err);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
const 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.sync= true;
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
|
||||
//queue up a bunch of requests to be sent synchronously
|
||||
for(var i=0; i<10; i++){
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'+i
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data,'\n\n');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc);
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
const 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.sync = true;
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
//fake some synch procedural code
|
||||
setTimeout(
|
||||
function(){
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
},
|
||||
3000
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
const 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 ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data,data.toString());
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
const 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', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
ipc.config.maxRetries= 10;
|
||||
ipc.config.tls={
|
||||
rejectUnauthorized:false
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'goodbye'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
const 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.maxRetries=10;
|
||||
ipc.config.tls={
|
||||
rejectUnauthorized:false
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
const 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.tls={
|
||||
public: __dirname+'/../../../local-node-ipc-certs/server.pub',
|
||||
private: __dirname+'/../../../local-node-ipc-certs/private/server.key'
|
||||
};
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from', (data.id), (data.message));
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection');
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
id:ipc.config.id
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
const 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.tls={
|
||||
rejectUnauthorized:false
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
const 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;
|
||||
//node-ipc will default to its local certs
|
||||
ipc.config.tls={
|
||||
rejectUnauthorized:false
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
const 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.tls={
|
||||
private: __dirname+'/../../../local-node-ipc-certs/private/client.key',
|
||||
public: __dirname+'/../../../local-node-ipc-certs/client.pub',
|
||||
rejectUnauthorized:false,
|
||||
trustedConnections: [
|
||||
__dirname+'/../../../local-node-ipc-certs/server.pub'
|
||||
]
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
const 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.tls={
|
||||
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: [
|
||||
__dirname+'/../../../local-node-ipc-certs/client.pub'
|
||||
]
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
const 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.networkHost='localhost';
|
||||
ipc.config.tls={
|
||||
private: __dirname+'/../../../local-node-ipc-certs/private/client.key',
|
||||
public: __dirname+'/../../../local-node-ipc-certs/client.pub',
|
||||
rejectUnauthorized:true,
|
||||
trustedConnections: [
|
||||
__dirname+'/../../../local-node-ipc-certs/server.pub'
|
||||
]
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
const 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.networkHost='localhost';
|
||||
ipc.config.tls={
|
||||
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: [
|
||||
__dirname+'/../../../local-node-ipc-certs/client.pub'
|
||||
]
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
const 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.tls={
|
||||
rejectUnauthorized:false
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
const 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.tls={
|
||||
public: __dirname+'/../../../local-node-ipc-certs/server.pub',
|
||||
private: __dirname+'/../../../local-node-ipc-certs/private/server.key'
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
const 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.sync= true;
|
||||
ipc.config.tls={
|
||||
rejectUnauthorized:false
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
|
||||
//queue up a bunch of requests to be sent synchronously
|
||||
for(var i=0; i<10; i++){
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'+i
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
const 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.sync= true;
|
||||
ipc.config.tls={
|
||||
public: __dirname+'/../../../local-node-ipc-certs/server.pub',
|
||||
private: __dirname+'/../../../local-node-ipc-certs/private/server.key'
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : ', data);
|
||||
setTimeout(
|
||||
function(){
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
data+' world!'
|
||||
);
|
||||
},
|
||||
3000
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'socket.disconnected',
|
||||
function(data,socket){
|
||||
console.log(arguments);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
const 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.config.networkHost='localhost';
|
||||
|
||||
ipc.config.tls={
|
||||
private: __dirname+'/../../../local-node-ipc-certs/private/client.key',
|
||||
public: __dirname+'/../../../local-node-ipc-certs/client.pub',
|
||||
rejectUnauthorized:true,
|
||||
trustedConnections: [
|
||||
__dirname+'/../../../local-node-ipc-certs/server.pub'
|
||||
]
|
||||
};
|
||||
|
||||
ipc.connectToNet(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data,data.toString());
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
const 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.config.networkHost='localhost';
|
||||
|
||||
ipc.config.tls={
|
||||
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: [
|
||||
__dirname+'/../../../local-node-ipc-certs/client.pub'
|
||||
]
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'connect',
|
||||
function(socket){
|
||||
console.log('connection detected');
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* Since there is no client relationship
|
||||
* with UDP sockets sockets are not kept
|
||||
* open.
|
||||
*
|
||||
* This means the order sockets are opened
|
||||
* is important.
|
||||
*
|
||||
* Start World first. Then you can start
|
||||
* hello or goodbye in any order you
|
||||
* choose.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.serveNet(
|
||||
8002, //we set the port here because the hello client and world server are already using the default of 8000 and the port 8001. So we can not bind to those while hello and world are connected to them.
|
||||
'udp4',
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Goodbye'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* Since there is no client relationship
|
||||
* with UDP sockets sockets are not kept
|
||||
* open.
|
||||
*
|
||||
* This means the order sockets are opened
|
||||
* is important.
|
||||
*
|
||||
* Start World first. Then you can start
|
||||
* hello or goodbye in any order you
|
||||
* choose.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
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(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* Since there is no client relationship
|
||||
* with UDP sockets sockets are not kept
|
||||
* open.
|
||||
*
|
||||
* This means the order sockets are opened
|
||||
* is important.
|
||||
*
|
||||
* Start World first. Then you can start
|
||||
* hello or goodbye in any order you
|
||||
* choose.
|
||||
*
|
||||
***************************************/
|
||||
|
||||
ipc.config.id = 'world';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
};
|
||||
|
||||
ipc.serveNet(
|
||||
'udp4',
|
||||
function(){
|
||||
console.log(123);
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling evryone how muchg I am loved!');
|
||||
ipc.server.broadcast(
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Everybody Loves The World! Got messages from hello and goodbye!'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc.server);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
const 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 = 'hello';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
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(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'Hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
const 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.serveNet(
|
||||
'udp4',
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
const 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 ', data, data.toString());
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
{
|
||||
address : 'localhost',
|
||||
port : ipc.config.networkPort
|
||||
},
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
const 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', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
const fs = require('fs');
|
||||
const ipc = require('../../node-ipc');
|
||||
|
||||
const socketPath = '/tmp/ipc.sock';
|
||||
|
||||
//loop forever so you can see the pid of the cluster sever change in the logs
|
||||
setInterval(
|
||||
function() {
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
socketPath,
|
||||
connecting
|
||||
);
|
||||
},
|
||||
2000
|
||||
);
|
||||
|
||||
function connecting(socket) {
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function() {
|
||||
ipc.of.world.emit(
|
||||
'currentDate',
|
||||
{
|
||||
message: new Date().toISOString()
|
||||
}
|
||||
);
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs');
|
||||
const ipc=require('../../../node-ipc');
|
||||
const cpuCount = require('os').cpus().length;
|
||||
const cluster = require('cluster');
|
||||
const socketPath = '/tmp/ipc.sock';
|
||||
|
||||
ipc.config.unlink = false;
|
||||
|
||||
if (cluster.isMaster) {
|
||||
if (fs.existsSync(socketPath)) {
|
||||
fs.unlinkSync(socketPath);
|
||||
}
|
||||
|
||||
for (let i = 0; i < cpuCount; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
}else{
|
||||
ipc.serve(
|
||||
socketPath,
|
||||
function() {
|
||||
ipc.server.on(
|
||||
'currentDate',
|
||||
function(data,socket) {
|
||||
console.log(`pid ${process.pid} got: `, data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
console.log(`pid ${process.pid} listening on ${socketPath}`);
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const 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='hex';
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
//make a 6 byte buffer for example
|
||||
const myBuffer=new Buffer(6).fill(0);
|
||||
|
||||
myBuffer.writeUInt16BE(0x02,0);
|
||||
myBuffer.writeUInt32BE(0xffeecc,2);
|
||||
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
myBuffer
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
const 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='hex';
|
||||
|
||||
ipc.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'connect',
|
||||
function(socket){
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
[0xaa]
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
[0x0d,0xee]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'goodbye';
|
||||
ipc.config.retry= 1500;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'goodbye'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
const 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.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
const 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;
|
||||
|
||||
var messages={
|
||||
goodbye:false,
|
||||
hello:false
|
||||
};
|
||||
|
||||
ipc.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from', (data.id), (data.message));
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection');
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
id:ipc.config.id
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry = 1000;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc.of.world.destroy);
|
||||
}
|
||||
);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
const 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.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
* You should start both hello and world
|
||||
* then you will see them communicating.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
ipc.config.id = 'hello';
|
||||
ipc.config.retry = 1000;
|
||||
ipc.config.sync= true;
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
|
||||
//queue up a bunch of requests to be sent synchronously
|
||||
for(var i=0; i<10; i++){
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : 'hello'+i
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
|
||||
console.log(ipc.of.world.destroy);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
const 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.sync= true;
|
||||
|
||||
ipc.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
setTimeout(
|
||||
function(){
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
{
|
||||
id : ipc.config.id,
|
||||
message : data.message+' world!'
|
||||
}
|
||||
);
|
||||
},
|
||||
2000
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
ipc.server.start();
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
const 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.connectTo(
|
||||
'world',
|
||||
function(){
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : ', data,data.toString());
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Generated
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
const 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.serve(
|
||||
function(){
|
||||
ipc.server.on(
|
||||
'connect',
|
||||
function(socket){
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'hello'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipc.server.start();
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const IPC = require('./services/IPC.js');
|
||||
|
||||
class IPCModule extends IPC{
|
||||
constructor(){
|
||||
super();
|
||||
//include IPC to make extensible
|
||||
Object.defineProperty(
|
||||
this,
|
||||
'IPC',
|
||||
{
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:IPC
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports=new IPCModule;
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"node-ipc@9.1.1",
|
||||
"C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer"
|
||||
]
|
||||
],
|
||||
"_from": "node-ipc@9.1.1",
|
||||
"_id": "node-ipc@9.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-FAyICv0sIRJxVp3GW5fzgaf9jwwRQxAKDJlmNFUL5hOy+W4X/I5AypyHoq0DXXbo9o/gt79gj++4cMr4jVWE/w==",
|
||||
"_location": "/node-ipc",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "node-ipc@9.1.1",
|
||||
"name": "node-ipc",
|
||||
"escapedName": "node-ipc",
|
||||
"rawSpec": "9.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "9.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.1.tgz",
|
||||
"_spec": "9.1.1",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer",
|
||||
"author": {
|
||||
"name": "Brandon Nozaki Miller"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/RIAEvangelist/node-ipc/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"event-pubsub": "4.3.0",
|
||||
"js-message": "1.0.5",
|
||||
"js-queue": "2.0.0"
|
||||
},
|
||||
"description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.",
|
||||
"devDependencies": {
|
||||
"codacy-coverage": "2.0.0",
|
||||
"istanbul": "0.4.1",
|
||||
"jasmine": "2.4.1",
|
||||
"node-cmd": "2.0.0"
|
||||
},
|
||||
"directories": {
|
||||
"example": "example"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"homepage": "http://riaevangelist.github.io/node-ipc/",
|
||||
"keywords": [
|
||||
"IPC",
|
||||
"Neural Networking",
|
||||
"Machine Learning",
|
||||
"inter",
|
||||
"process",
|
||||
"communication",
|
||||
"unix",
|
||||
"windows",
|
||||
"win",
|
||||
"socket",
|
||||
"TCP",
|
||||
"UDP",
|
||||
"domain",
|
||||
"sockets",
|
||||
"threaded",
|
||||
"communication",
|
||||
"multi",
|
||||
"process",
|
||||
"shared",
|
||||
"memory"
|
||||
],
|
||||
"license": "DBAD",
|
||||
"main": "node-ipc.js",
|
||||
"name": "node-ipc",
|
||||
"pre-commit": [
|
||||
"cover"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/RIAEvangelist/node-ipc.git"
|
||||
},
|
||||
"scripts": {
|
||||
"cover": "istanbul cover -x **/spec/** -dir ./spec/coverage jasmine",
|
||||
"coverup": "cat ./spec/coverage/lcov.info | codacy-coverage",
|
||||
"test": "istanbul cover -x **/spec/** -dir ./spec/coverage jasmine",
|
||||
"test-windows": "istanbul cover -x **/spec/** -dir ./spec/coverage ./node_modules/jasmine/bin/jasmine.js"
|
||||
},
|
||||
"version": "9.1.1"
|
||||
}
|
||||
+337
@@ -0,0 +1,337 @@
|
||||
'use strict';
|
||||
|
||||
const Defaults = require('../entities/Defaults.js'),
|
||||
Client = require('../dao/client.js'),
|
||||
Server = require('../dao/socketServer.js'),
|
||||
util = require('util');
|
||||
|
||||
class IPC{
|
||||
constructor(){
|
||||
Object.defineProperties(
|
||||
this,
|
||||
{
|
||||
config : {
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
value:new Defaults
|
||||
},
|
||||
connectTo : {
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:connect
|
||||
},
|
||||
connectToNet: {
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:connectNet
|
||||
},
|
||||
disconnect : {
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:disconnect
|
||||
},
|
||||
serve : {
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:serve
|
||||
},
|
||||
serveNet : {
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:serveNet
|
||||
},
|
||||
of : {
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
value:{}
|
||||
},
|
||||
server : {
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
configurable:true,
|
||||
value:false
|
||||
},
|
||||
log : {
|
||||
enumerable:true,
|
||||
writable:false,
|
||||
value:log
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function log(...args){
|
||||
if(this.config.silent){
|
||||
return;
|
||||
}
|
||||
|
||||
for(let i=0, count=args.length; i<count; i++){
|
||||
if(typeof args[i] != 'object'){
|
||||
continue;
|
||||
}
|
||||
|
||||
args[i]=util.inspect(
|
||||
args[i],
|
||||
{
|
||||
depth:this.config.logDepth,
|
||||
colors:this.config.logInColor
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
this.config.logger(
|
||||
args.join(' ')
|
||||
);
|
||||
}
|
||||
|
||||
function disconnect(id){
|
||||
if(!this.of[id]){
|
||||
return;
|
||||
}
|
||||
|
||||
this.of[id].explicitlyDisconnected=true;
|
||||
|
||||
this.of[id].off('*','*');
|
||||
if(this.of[id].socket){
|
||||
if(this.of[id].socket.destroy){
|
||||
this.of[id].socket.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
delete this.of[id];
|
||||
}
|
||||
|
||||
function serve(path,callback){
|
||||
if(typeof path=='function'){
|
||||
callback=path;
|
||||
path=false;
|
||||
}
|
||||
if(!path){
|
||||
this.log(
|
||||
'Server path not specified, so defaulting to',
|
||||
'ipc.config.socketRoot + ipc.config.appspace + ipc.config.id',
|
||||
this.config.socketRoot+this.config.appspace+this.config.id
|
||||
);
|
||||
path=this.config.socketRoot+this.config.appspace+this.config.id;
|
||||
}
|
||||
|
||||
if(!callback){
|
||||
callback=emptyCallback;
|
||||
}
|
||||
|
||||
this.server=new Server(
|
||||
path,
|
||||
this.config,
|
||||
log
|
||||
);
|
||||
|
||||
this.server.on(
|
||||
'start',
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function emptyCallback(){
|
||||
//Do Nothing
|
||||
}
|
||||
|
||||
function serveNet(host,port,UDPType,callback){
|
||||
if(typeof host=='number'){
|
||||
callback=UDPType;
|
||||
UDPType=port;
|
||||
port=host;
|
||||
host=false;
|
||||
}
|
||||
if(typeof host=='function'){
|
||||
callback=host;
|
||||
UDPType=false;
|
||||
host=false;
|
||||
port=false;
|
||||
}
|
||||
if(!host){
|
||||
this.log(
|
||||
'Server host not specified, so defaulting to',
|
||||
'ipc.config.networkHost',
|
||||
this.config.networkHost
|
||||
);
|
||||
host=this.config.networkHost;
|
||||
}
|
||||
if(host.toLowerCase()=='udp4' || host.toLowerCase()=='udp6'){
|
||||
callback=port;
|
||||
UDPType=host.toLowerCase();
|
||||
port=false;
|
||||
host=this.config.networkHost;
|
||||
}
|
||||
|
||||
if(typeof port=='string'){
|
||||
callback=UDPType;
|
||||
UDPType=port;
|
||||
port=false;
|
||||
}
|
||||
if(typeof port=='function'){
|
||||
callback=port;
|
||||
UDPType=false;
|
||||
port=false;
|
||||
}
|
||||
if(!port){
|
||||
this.log(
|
||||
'Server port not specified, so defaulting to',
|
||||
'ipc.config.networkPort',
|
||||
this.config.networkPort
|
||||
);
|
||||
port=this.config.networkPort;
|
||||
}
|
||||
|
||||
if(typeof UDPType=='function'){
|
||||
callback=UDPType;
|
||||
UDPType=false;
|
||||
}
|
||||
|
||||
if(!callback){
|
||||
callback=emptyCallback;
|
||||
}
|
||||
|
||||
this.server=new Server(
|
||||
host,
|
||||
this.config,
|
||||
log,
|
||||
port
|
||||
);
|
||||
|
||||
if(UDPType){
|
||||
this.server[UDPType]=true;
|
||||
if(UDPType === "udp4" && host === "::1") {
|
||||
// bind udp4 socket to an ipv4 address
|
||||
this.server.path = "127.0.0.1";
|
||||
}
|
||||
}
|
||||
|
||||
this.server.on(
|
||||
'start',
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function connect(id,path,callback){
|
||||
if(typeof path == 'function'){
|
||||
callback=path;
|
||||
path=false;
|
||||
}
|
||||
|
||||
if(!callback){
|
||||
callback=emptyCallback;
|
||||
}
|
||||
|
||||
if(!id){
|
||||
this.log(
|
||||
'Service id required',
|
||||
'Requested service connection without specifying service id. Aborting connection attempt'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!path){
|
||||
this.log(
|
||||
'Service path not specified, so defaulting to',
|
||||
'ipc.config.socketRoot + ipc.config.appspace + id',
|
||||
(this.config.socketRoot+this.config.appspace+id).data
|
||||
);
|
||||
path=this.config.socketRoot+this.config.appspace+id;
|
||||
}
|
||||
|
||||
if(this.of[id]){
|
||||
if(!this.of[id].socket.destroyed){
|
||||
this.log(
|
||||
'Already Connected to',
|
||||
id,
|
||||
'- So executing success without connection'
|
||||
);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
this.of[id].socket.destroy();
|
||||
}
|
||||
|
||||
this.of[id] = new Client(this.config,this.log);
|
||||
this.of[id].id = id;
|
||||
this.of[id].path = path;
|
||||
|
||||
this.of[id].connect();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
function connectNet(id,host,port,callback){
|
||||
if(!id){
|
||||
this.log(
|
||||
'Service id required',
|
||||
'Requested service connection without specifying service id. Aborting connection attempt'
|
||||
);
|
||||
return;
|
||||
}
|
||||
if(typeof host=='number'){
|
||||
callback=port;
|
||||
port=host;
|
||||
host=false;
|
||||
}
|
||||
if(typeof host=='function'){
|
||||
callback=host;
|
||||
host=false;
|
||||
port=false;
|
||||
}
|
||||
if(!host){
|
||||
this.log(
|
||||
'Server host not specified, so defaulting to',
|
||||
'ipc.config.networkHost',
|
||||
this.config.networkHost
|
||||
);
|
||||
host=this.config.networkHost;
|
||||
}
|
||||
|
||||
if(typeof port=='function'){
|
||||
callback=port;
|
||||
port=false;
|
||||
}
|
||||
if(!port){
|
||||
this.log(
|
||||
'Server port not specified, so defaulting to',
|
||||
'ipc.config.networkPort',
|
||||
this.config.networkPort
|
||||
);
|
||||
port=this.config.networkPort;
|
||||
}
|
||||
|
||||
if(typeof callback == 'string'){
|
||||
UDPType=callback;
|
||||
callback=false;
|
||||
}
|
||||
if(!callback){
|
||||
callback=emptyCallback;
|
||||
}
|
||||
|
||||
if(this.of[id]){
|
||||
if(!this.of[id].socket.destroyed){
|
||||
|
||||
this.log(
|
||||
'Already Connected to',
|
||||
id,
|
||||
'- So executing success without connection'
|
||||
);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
this.of[id].socket.destroy();
|
||||
}
|
||||
|
||||
this.of[id] = new Client(this.config,this.log);
|
||||
this.of[id].id = id;
|
||||
this.of[id].path = host;
|
||||
this.of[id].port = port;
|
||||
|
||||
this.of[id].connect();
|
||||
|
||||
callback(this);
|
||||
}
|
||||
|
||||
module.exports=IPC;
|
||||
Reference in new issue
Block a user