major revisions to binary, hex and other rawBuffer sockets
This commit is contained in:
parent
12ea8bfed7
commit
df0c6407c1
50 changed files with 388 additions and 246 deletions
134
README.md
134
README.md
|
@ -37,6 +37,7 @@ You may want to install jasmine and istanbul globally with ` sudo npm install -g
|
|||
#### Contents
|
||||
|
||||
1. [Types of IPC Sockets and Supporting OS](#types-of-ipc-sockets)
|
||||
1. [IPC Config](#ipc-config)
|
||||
2. [IPC Methods](#ipc-methods)
|
||||
1. [log](#log)
|
||||
2. [connectTo](#connectto)
|
||||
|
@ -46,13 +47,14 @@ You may want to install jasmine and istanbul globally with ` sudo npm install -g
|
|||
6. [serveNet](#servenet)
|
||||
3. [IPC Stores and Default Variables](#ipc-stores-and-default-variables)
|
||||
4. [IPC Events](#ipc-events)
|
||||
5. [Basic Examples](#basic-examples)
|
||||
5. [Multiple IPC instances](#multiple-ipc-instances)
|
||||
6. [Basic Examples](#basic-examples)
|
||||
1. [Server for Unix||Windows Sockets & TCP Sockets](#server-for-unix-sockets--tcp-sockets)
|
||||
2. [Client for Unix||Windows Sockets & TCP Sockets](#client-for-unix-sockets--tcp-sockets)
|
||||
4. [Server & Client for UDP Sockets](#server--client-for-udp-sockets)
|
||||
5. [Raw Buffers or Binary Sockets](#raw-buffer-or-binary-sockets)
|
||||
6. [Working with TLS/SSL Socket Servers & Clients](https://github.com/RIAEvangelist/node-ipc/tree/master/example/TLSSocket)
|
||||
7. [Advanced Examples](https://github.com/RIAEvangelist/node-ipc/tree/master/example)
|
||||
5. [Raw Buffers, Real Time and / or Binary Sockets](#raw-buffer-or-binary-sockets)
|
||||
7. [Working with TLS/SSL Socket Servers & Clients](https://github.com/RIAEvangelist/node-ipc/tree/master/example/TLSSocket)
|
||||
8. [Node Code Examples](https://github.com/RIAEvangelist/node-ipc/tree/master/example)
|
||||
|
||||
|
||||
----
|
||||
|
@ -73,6 +75,8 @@ You may want to install jasmine and istanbul globally with ` sudo npm install -g
|
|||
|
||||
----
|
||||
|
||||
#### IPC Config
|
||||
|
||||
`ipc.config`
|
||||
|
||||
Set these variables in the `ipc.config` scope to overwrite or set default values.
|
||||
|
@ -89,6 +93,8 @@ Set these variables in the `ipc.config` scope to overwrite or set default values
|
|||
rawBuffer : false,
|
||||
sync : false,
|
||||
silent : false,
|
||||
logInColor : true,
|
||||
logDepth : 5,
|
||||
maxConnections : 100,
|
||||
retry : 500,
|
||||
maxRetries : false,
|
||||
|
@ -104,10 +110,12 @@ Set these variables in the `ipc.config` scope to overwrite or set default values
|
|||
| id | the id of this socket or service |
|
||||
| networkHost| the local or remote host on which TCP, TLS or UDP Sockets should connect |
|
||||
| networkPort| the default port on which TCP, TLS, or UDP sockets should connect |
|
||||
| encoding | the default encoding for data sent on sockets. Mostly used if rawBuffer is set to true. Valid values are : ` ascii` ` utf8 ` ` utf16le` ` ucs2` ` base64` ` hex ` .
|
||||
| encoding | the default encoding for data sent on sockets. Mostly used if rawBuffer is set to true. Valid values are : ` ascii` ` utf8 ` ` utf16le` ` ucs2` ` base64` ` hex ` . |
|
||||
| rawBuffer| if true, data will be sent and received as a raw node ` Buffer ` __NOT__ an ` Object ` as JSON. This is great for Binary or hex IPC, and communicating with other processes in languages like C and C++ |
|
||||
| sync | synchronous requests. Clients will not send new requests until the server answers. |
|
||||
| silent | turn on/off logging default is false which means logging is on |
|
||||
| logInColor | turn on/off util.inspect colors for ipc.log |
|
||||
| logDepth | set the depth for util.inspect during ipc.log |
|
||||
| maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. |
|
||||
| retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. |
|
||||
| maxRetries | if set, it represents the maximum number of retries after each disconnect before giving up and completely killing a specific connection |
|
||||
|
@ -123,37 +131,14 @@ These methods are available in the IPC Scope.
|
|||
|
||||
`ipc.log(a,b,c,d,e...);`
|
||||
|
||||
ipc.log will accept any number of arguments and if `ipc.config.silent` is not set, it will concat them all with a sincle space ' ' between them and then log them to the console. This is fast because it prevents any concatenation from happening if the ipc is set to silent. That way if you leave your logging in place it should not effect performance.
|
||||
ipc.log will accept any number of arguments and if `ipc.config.silent` is not set, it will concat them all with a single space ' ' between them and then log them to the console. This is fast because it prevents any concatenation from happening if the ipc.config.silent is set ` true `. That way if you leave your logging in place it should have almost no effect on performance.
|
||||
|
||||
The log also supports [colors](https://github.com/Marak/colors.js) implementation. All of the available styles are supported and the theme styles are as follows :
|
||||
The log also uses util.inspect You can control if it should log in color as well as the log depth via ` ipc.config `
|
||||
|
||||
```javascript
|
||||
|
||||
{
|
||||
good : 'green',
|
||||
notice : 'yellow',
|
||||
warn : 'red',
|
||||
error : 'redBG',
|
||||
debug : 'magenta',
|
||||
variable: 'cyan',
|
||||
data : 'blue'
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
You can override any of these settings by requireing colors and setting the theme as follows :
|
||||
|
||||
```javascript
|
||||
|
||||
var colors=require('colors');
|
||||
|
||||
colors.setTheme(
|
||||
{
|
||||
good : 'zebra',
|
||||
notice : 'redBG',
|
||||
...
|
||||
}
|
||||
);
|
||||
ipc.config.logInColor=true; //default
|
||||
ipc.config.logDepth=5; //default
|
||||
|
||||
```
|
||||
|
||||
|
@ -474,6 +459,38 @@ or specifying everything UDP
|
|||
|***your event type***|***your event data***|triggered when a JSON message is received. The event name will be the type string from your message and the param will be the data object from your message eg : ` { type:'myEvent',data:{a:1}} ` |
|
||||
||||
|
||||
|
||||
### Multiple IPC Instances
|
||||
|
||||
Sometimes you might need explicit and independent instances of node-ipc. Just for such scenarios we have exposed the core IPC class on the IPC singleton.
|
||||
|
||||
```javascript
|
||||
|
||||
const RawIPC=require('node-ipc').IPC;
|
||||
const ipc=new RawIPC;
|
||||
const someOtherExplicitIPC=new RawIPC;
|
||||
|
||||
|
||||
//OR
|
||||
|
||||
const ipc=require('node-ipc');
|
||||
const someOtherExplicitIPC=new ipc.IPC;
|
||||
|
||||
|
||||
//setting explicit configs
|
||||
|
||||
//keep one silent and the other verbose
|
||||
ipc.config.silent=true;
|
||||
someOtherExplicitIPC.config.silent=true;
|
||||
|
||||
//make one a raw binary and the other json based ipc
|
||||
ipc.config.rawBuffer=false;
|
||||
|
||||
someOtherExplicitIPC.config.rawBuffer=true;
|
||||
someOtherExplicitIPC.config.encoding='hex';
|
||||
|
||||
```
|
||||
|
||||
|
||||
----
|
||||
### Basic Examples
|
||||
You can find [Advanced Examples](https://github.com/RIAEvangelist/node-ipc/tree/master/example) in the examples folder. In the examples you will find more complex demos including multi client examples.
|
||||
|
@ -630,7 +647,7 @@ This is the most basic example which will work for both local and remote UDP Soc
|
|||
```
|
||||
|
||||
#### Raw Buffer or Binary Sockets
|
||||
Binary or Buffer sockets can be used with any of the above socket types, however the way data events are emit is ***slightly*** different.
|
||||
Binary or Buffer sockets can be used with any of the above socket types, however the way data events are emit is ***slightly*** different. These may come in handy if working with embedded systems or C / C++ processes. You can even make sure to match C or C++ string typing.
|
||||
|
||||
When setting up a rawBuffer socket you must specify it as such :
|
||||
|
||||
|
@ -669,6 +686,9 @@ emit byte array buffer :
|
|||
|
||||
```javascript
|
||||
|
||||
//hex encoding may work best for this.
|
||||
ipc.config.encoding='hex';
|
||||
|
||||
//server
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
|
@ -682,10 +702,12 @@ emit byte array buffer :
|
|||
|
||||
```
|
||||
|
||||
emit hex array buffer :
|
||||
emit binary or hex array buffer, this is best for real time data transfer, especially whan connecting to C or C++ processes, or embedded systems :
|
||||
|
||||
```javascript
|
||||
|
||||
ipc.config.encoding='hex';
|
||||
|
||||
//server
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
|
@ -699,5 +721,49 @@ emit hex array buffer :
|
|||
|
||||
```
|
||||
|
||||
Writing explicit buffers, int types, doubles, floats etc. as well as big endian and little endian data to raw buffer nostly valuable when connecting to C or C++ processes, or embedded systems (see more detailed info on buffers as well as UInt, Int, double etc. here)[https://nodejs.org/api/buffer.html]:
|
||||
|
||||
```javascript
|
||||
|
||||
ipc.config.encoding='hex';
|
||||
|
||||
//make a 6 byte buffer for example
|
||||
const myBuffer=new Buffer(6).fill(0);
|
||||
|
||||
//fill the first 2 bytes with a 16 bit (2 byte) short unsigned int
|
||||
|
||||
//write a UInt16 (2 byte or short) as Big Endian
|
||||
myBuffer.writeUInt16BE(
|
||||
2, //value to write
|
||||
0 //offset in bytes
|
||||
);
|
||||
//OR
|
||||
myBuffer.writeUInt16LE(0x2,0);
|
||||
//OR
|
||||
myBuffer.writeUInt16LE(0x02,0);
|
||||
|
||||
//fill the remaining 4 bytes with a 32 bit (4 byte) long unsigned int
|
||||
|
||||
//write a UInt32 (4 byte or long) as Big Endian
|
||||
myBuffer.writeUInt32BE(
|
||||
16772812, //value to write
|
||||
2 //offset in bytes
|
||||
);
|
||||
//OR
|
||||
myBuffer.writeUInt32BE(0xffeecc,0)
|
||||
|
||||
//server
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
myBuffer
|
||||
);
|
||||
|
||||
//client
|
||||
ipc.server.emit(
|
||||
myBuffer
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
#### Licensed under DBAD license
|
||||
See the [DBAD license](https://github.com/philsturgeon/dbad) in your language or our [licence.md](https://github.com/RIAEvangelist/node-phidget-API/blob/master/license.md) file.
|
||||
|
|
|
@ -25,14 +25,14 @@ function init(config,log){
|
|||
}
|
||||
|
||||
function emit(type,data){
|
||||
this.log('dispatching event to '.debug, (this.id).variable, this.path.variable,' : ', type.data,',', 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.encoding);
|
||||
message=new Buffer(type,this.config.encoding);
|
||||
}else{
|
||||
message=eventParser.format(message);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ function emit(type,data){
|
|||
}
|
||||
|
||||
function syncEmit(message){
|
||||
this.log('dispatching event to '.debug, (this.id).variable, this.path.variable,' : ', message.data);
|
||||
this.log('dispatching event to ', this.id, this.path, ' : ', message);
|
||||
this.socket.write(message);
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,14 @@ function connect(){
|
|||
//init client object for scope persistance especially inside of socket events.
|
||||
let client=this;
|
||||
|
||||
client.log('requested connection to '.debug, client.id.variable, client.path.variable);
|
||||
client.log('requested connection to ', client.id, client.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: ', client.id ,' client has not specified socket path it wishes to connect to.');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!client.port){
|
||||
client.log('Connecting client on Unix Socket :'.debug, client.path.variable);
|
||||
client.log('Connecting client on Unix Socket :', client.path);
|
||||
|
||||
let path = client.path;
|
||||
|
||||
|
@ -79,7 +79,7 @@ function connect(){
|
|||
);
|
||||
}else{
|
||||
if(!client.config.tls){
|
||||
client.log('Connecting client via TCP to'.debug, client.path.variable ,client.port);
|
||||
client.log('Connecting client via TCP to', client.path ,client.port);
|
||||
client.socket = net.connect(
|
||||
{
|
||||
port:client.port,
|
||||
|
@ -87,7 +87,7 @@ function connect(){
|
|||
}
|
||||
);
|
||||
}else{
|
||||
client.log('Connecting client via TLS to'.debug, client.path.variable ,client.port,client.config.tls);
|
||||
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);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ function connect(){
|
|||
client.socket.on(
|
||||
'error',
|
||||
function(err){
|
||||
client.log('\n\n######\nerror: '.error, err);
|
||||
client.log('\n\n######\nerror: ', err);
|
||||
client.trigger('error', err);
|
||||
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ function connect(){
|
|||
client.socket.on(
|
||||
'close',
|
||||
function connectionClosed(){
|
||||
client.log('connection closed'.notice ,client.id.variable , client.path.variable,
|
||||
`${client.retriesRemaining} tries remaining of ${client.config.maxRetries}`
|
||||
client.log('connection closed' ,client.id , client.path,
|
||||
client.retriesRemaining, 'tries remaining of', client.config.maxRetries
|
||||
);
|
||||
|
||||
if(
|
||||
|
@ -148,8 +148,8 @@ function connect(){
|
|||
){
|
||||
client.trigger('disconnect');
|
||||
client.log(
|
||||
(client.config.id).variable,
|
||||
'exceeded connection rety amount of'.warn,
|
||||
(client.config.id),
|
||||
'exceeded connection rety amount of',
|
||||
' or stopRetrying flag set.'
|
||||
);
|
||||
|
||||
|
@ -186,11 +186,11 @@ function connect(){
|
|||
client.socket.on(
|
||||
'data',
|
||||
function(data) {
|
||||
client.log('## recieved events ##'.rainbow);
|
||||
client.log('## recieved events ##');
|
||||
if(client.config.rawBuffer){
|
||||
client.trigger(
|
||||
'data',
|
||||
new Buffer(data,this.encoding)
|
||||
new Buffer(data,client.config.encoding)
|
||||
);
|
||||
if(!client.config.sync){
|
||||
return;
|
||||
|
@ -207,7 +207,7 @@ function connect(){
|
|||
data=(this.ipcBuffer+=data);
|
||||
|
||||
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
|
||||
client.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice);
|
||||
client.log('Messages are large, You may want to consider smaller messages.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ function connect(){
|
|||
let message=new Message;
|
||||
message.load(events[i]);
|
||||
|
||||
client.log('detected event of type '.debug, message.type.data, message.data);
|
||||
client.log('detected event', message.type, message.data);
|
||||
client.trigger(
|
||||
message.type,
|
||||
message.data
|
||||
|
|
|
@ -9,14 +9,15 @@ const net = require('net'),
|
|||
Message = require('js-message');
|
||||
|
||||
function emit(socket, type, data){
|
||||
this.log('dispatching event to socket'.debug, ' : ', type.data, data);
|
||||
this.log('dispatching event to socket', ' : ', type, data);
|
||||
|
||||
let message=new Message;
|
||||
message.type=type;
|
||||
message.data=data;
|
||||
|
||||
if(this.config.rawBuffer){
|
||||
message=new Buffer(type,this.encoding);
|
||||
console.log(this.config.encoding)
|
||||
message=new Buffer(type,this.config.encoding);
|
||||
}else{
|
||||
message=eventParser.format(message);
|
||||
}
|
||||
|
@ -40,13 +41,13 @@ function emit(socket, 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 ', 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.encoding);
|
||||
message=new Buffer(type,this.config.encoding);
|
||||
}else{
|
||||
message=eventParser.format(message);
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ function init(path,config,log,port){
|
|||
},
|
||||
start : function start(){
|
||||
if(!this.path){
|
||||
server.log('Socket Server Path not specified, refusing to start'.warn);
|
||||
server.log('Socket Server Path not specified, refusing to start');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -93,8 +94,8 @@ function init(path,config,log,port){
|
|||
this.path,
|
||||
function () {
|
||||
server.log(
|
||||
'starting server on '.debug,server.path.variable,
|
||||
((server.port)?`:${server.port}`:'').variable
|
||||
'starting server on ',server.path,
|
||||
((server.port)?`:${server.port}`:'')
|
||||
);
|
||||
|
||||
if(!server.udp4 && !server.udp6){
|
||||
|
@ -103,7 +104,7 @@ function init(path,config,log,port){
|
|||
serverCreated
|
||||
);
|
||||
}else{
|
||||
server.log('starting TLS server'.debug,server.config.tls);
|
||||
server.log('starting TLS server',server.config.tls);
|
||||
if(server.config.tls.private){
|
||||
server.config.tls.key=fs.readFileSync(server.config.tls.private);
|
||||
}else{
|
||||
|
@ -144,7 +145,7 @@ function init(path,config,log,port){
|
|||
socket.address,
|
||||
function(err, bytes) {
|
||||
if(err){
|
||||
server.log('error writing data to socket'.warn,err);
|
||||
server.log('error writing data to socket',err);
|
||||
server.trigger(
|
||||
'error',
|
||||
function(err){
|
||||
|
@ -171,7 +172,7 @@ function init(path,config,log,port){
|
|||
server.server.on(
|
||||
'error',
|
||||
function(err){
|
||||
server.log('server error'.warn,err);
|
||||
server.log('server error',err);
|
||||
|
||||
server.trigger(
|
||||
'error',
|
||||
|
@ -189,7 +190,7 @@ function init(path,config,log,port){
|
|||
socket.setEncoding(server.config.encoding);
|
||||
}
|
||||
|
||||
server.log('## socket connection to server detected ##'.rainbow);
|
||||
server.log('## socket connection to server detected ##');
|
||||
socket.on(
|
||||
'close',
|
||||
function(socket){
|
||||
|
@ -203,7 +204,7 @@ function init(path,config,log,port){
|
|||
socket.on(
|
||||
'error',
|
||||
function(err){
|
||||
server.log('server socket error'.warn,err);
|
||||
server.log('server socket error',err);
|
||||
|
||||
server.trigger('error',err);
|
||||
}
|
||||
|
@ -214,7 +215,7 @@ function init(path,config,log,port){
|
|||
function(data,UDPSocket){
|
||||
let sock=((server.udp4 || server.udp6)? UDPSocket : socket);
|
||||
if(server.config.rawBuffer){
|
||||
data=new Buffer(data,this.encoding);
|
||||
data=new Buffer(data,server.config.encoding);
|
||||
server.trigger(
|
||||
'data',
|
||||
data,
|
||||
|
@ -230,7 +231,7 @@ function init(path,config,log,port){
|
|||
data=(this.ipcBuffer+=data);
|
||||
|
||||
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('Messages are large, You may want to consider smaller messages.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -242,7 +243,7 @@ function init(path,config,log,port){
|
|||
let message=new Message;
|
||||
message.load(data.shift());
|
||||
|
||||
server.log('received event of : '.debug,message.type.data,message.data);
|
||||
server.log('received event of : ',message.type,message.data);
|
||||
|
||||
if(message.data.id){
|
||||
sock.id=message.data.id;
|
||||
|
@ -264,11 +265,11 @@ function init(path,config,log,port){
|
|||
return;
|
||||
}
|
||||
|
||||
server.log('Received UDP message from '.debug, rinfo.address.variable, rinfo.port);
|
||||
server.log('Received UDP message from ', rinfo.address, rinfo.port);
|
||||
let data;
|
||||
|
||||
if(server.config.rawSocket){
|
||||
data=new Buffer(msg,this.encoding);
|
||||
data=new Buffer(msg,server.config.encoding);
|
||||
}else{
|
||||
data=msg.toString();
|
||||
}
|
||||
|
@ -291,7 +292,7 @@ function init(path,config,log,port){
|
|||
}
|
||||
|
||||
if(!port){
|
||||
server.log('starting server as'.debug, 'Unix || Windows Socket'.variable);
|
||||
server.log('starting server as', 'Unix || Windows Socket');
|
||||
if (process.platform ==='win32'){
|
||||
server.path = server.path.replace(/^\//, '');
|
||||
server.path = server.path.replace(/\//g, '-');
|
||||
|
@ -307,7 +308,7 @@ function init(path,config,log,port){
|
|||
}
|
||||
|
||||
if(!server.udp4 && !server.udp6){
|
||||
server.log('starting server as'.debug, (server.config.tls?'TLS':'TCP').variable);
|
||||
server.log('starting server as', (server.config.tls?'TLS':'TCP'));
|
||||
server.server.listen(
|
||||
server.port,
|
||||
server.path,
|
||||
|
@ -316,7 +317,7 @@ function init(path,config,log,port){
|
|||
return;
|
||||
}
|
||||
|
||||
server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable);
|
||||
server.log('starting server as',((server.udp4)? 'udp4':'udp6'));
|
||||
server.server.bind(
|
||||
server.port,
|
||||
server.path
|
||||
|
@ -352,7 +353,7 @@ function init(path,config,log,port){
|
|||
destroyedSocketId=socket.id;
|
||||
}
|
||||
|
||||
server.log('socket disconnected'.notice,destroyedSocketId.toString().variable);
|
||||
server.log('socket disconnected',destroyedSocketId.toString());
|
||||
|
||||
if(socket && socket.destroy){
|
||||
socket.destroy();
|
||||
|
|
|
@ -56,6 +56,16 @@ class Defaults{
|
|||
writable:true,
|
||||
value:false
|
||||
},
|
||||
logDepth:{
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
value:5
|
||||
},
|
||||
logInColor:{
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
value:true
|
||||
},
|
||||
maxConnections : {
|
||||
enumerable:true,
|
||||
writable:true,
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
class LogColors{
|
||||
constructor(){
|
||||
this.good='green';
|
||||
this.notice='yellow';
|
||||
this.warn='red';
|
||||
this.error='redBG';
|
||||
this.debug='magenta';
|
||||
this.variable='cyan';
|
||||
this.data='blue';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports=LogColors;
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -30,13 +30,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -30,19 +30,19 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data.message);
|
||||
ipc.log('got a message from world : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -20,7 +20,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
ipc.log('got a message from', (data.id), (data.message));
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
|
@ -32,7 +32,7 @@ ipc.serveNet(
|
|||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection'.good);
|
||||
ipc.log('got all required events, telling clients to kill connection');
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
|
@ -26,13 +26,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
|
@ -37,7 +37,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'error',
|
||||
function(err){
|
||||
ipc.log('Got an ERROR!'.warn,err);
|
||||
ipc.log('Got an ERROR!',err);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
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++){
|
||||
|
@ -31,13 +31,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data,'\n\n');
|
||||
ipc.log('got a message from world : ', data,'\n\n');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
//fake some synch procedural code
|
||||
setTimeout(
|
||||
function(){
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -18,7 +18,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'hello'
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data,data.toString());
|
||||
ipc.log('got a message from world : ', data,data.toString());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message'.debug, data,data.toString());
|
||||
ipc.log('got a message', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -20,7 +20,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -33,13 +33,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -20,7 +20,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -33,19 +33,19 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data.message);
|
||||
ipc.log('got a message from world : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -24,7 +24,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
ipc.log('got a message from', (data.id), (data.message));
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
|
@ -36,7 +36,7 @@ ipc.serveNet(
|
|||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection'.good);
|
||||
ipc.log('got all required events, telling clients to kill connection');
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
|
@ -29,13 +29,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -24,7 +24,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
|
@ -34,13 +34,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -25,7 +25,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -25,7 +25,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
|
@ -35,13 +35,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -26,7 +26,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
'hello'
|
||||
|
@ -29,13 +29,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -20,7 +20,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
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++){
|
||||
|
@ -34,13 +34,13 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -20,7 +20,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message : '.debug, data);
|
||||
ipc.log('got a message : ', data);
|
||||
setTimeout(
|
||||
function(){
|
||||
ipc.server.emit(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -28,7 +28,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'hello'
|
||||
);
|
||||
|
@ -38,7 +38,7 @@ ipc.connectToNet(
|
|||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data,data.toString());
|
||||
ipc.log('got a message from world : ', data,data.toString());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -40,7 +40,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message'.debug, data,data.toString());
|
||||
ipc.log('got a message', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -26,7 +26,7 @@ ipc.serveNet(
|
|||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -26,7 +26,7 @@ ipc.serveNet(
|
|||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -30,7 +30,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
|
@ -42,7 +42,7 @@ ipc.serveNet(
|
|||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling evryone how muchg I am loved!'.good);
|
||||
ipc.log('got all required events, telling evryone how muchg I am loved!');
|
||||
ipc.server.broadcast(
|
||||
'message',
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -30,7 +30,7 @@ ipc.serveNet(
|
|||
'message',
|
||||
function(data){
|
||||
ipc.log('got Data');
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -25,11 +25,10 @@ ipc.config.retry= 1500;
|
|||
ipc.serveNet(
|
||||
'udp4',
|
||||
function(){
|
||||
console.log(123);
|
||||
ipc.server.on(
|
||||
'message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
||||
ipc.log('got a message from ', data.id ,' : ', data.message);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'message',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world '.debug, data, data.toString());
|
||||
ipc.log('got a message from world ', data, data.toString());
|
||||
}
|
||||
);
|
||||
ipc.server.emit(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -30,7 +30,7 @@ ipc.serveNet(
|
|||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message'.debug, data,data.toString());
|
||||
ipc.log('got a message', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
|
|
43
example/rawBuffer/hello-client.js
Normal file
43
example/rawBuffer/hello-client.js
Normal file
|
@ -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
example/rawBuffer/world.server.js
Normal file
40
example/rawBuffer/world.server.js
Normal file
|
@ -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();
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -29,13 +29,13 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -29,19 +29,19 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'kill.connection',
|
||||
function(data){
|
||||
ipc.log('world requested kill.connection'.notice);
|
||||
ipc.log('world requested kill.connection');
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -20,7 +20,7 @@ ipc.serve(
|
|||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
ipc.log('got a message from', (data.id), (data.message));
|
||||
messages[data.id]=true;
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
|
@ -32,7 +32,7 @@ ipc.serve(
|
|||
);
|
||||
|
||||
if(messages.hello && messages.goodbye){
|
||||
ipc.log('got all required events, telling clients to kill connection'.good);
|
||||
ipc.log('got all required events, telling clients to kill connection');
|
||||
ipc.server.broadcast(
|
||||
'kill.connection',
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'app.message',
|
||||
{
|
||||
|
@ -29,13 +29,13 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -15,7 +15,6 @@ ipc.serve(
|
|||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
//ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'app.message',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
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++){
|
||||
|
@ -34,13 +34,13 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function(){
|
||||
ipc.log('disconnected from world'.notice);
|
||||
ipc.log('disconnected from world');
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'app.message',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data);
|
||||
ipc.log('got a message from world : ', data);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -16,8 +16,6 @@ ipc.serve(
|
|||
ipc.server.on(
|
||||
'app.message',
|
||||
function(data,socket){
|
||||
//ipc.log('got a message from'.debug, (data.id).variable, (data.message).data);
|
||||
|
||||
setTimeout(
|
||||
function(){
|
||||
ipc.server.emit(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -18,7 +18,7 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'connect',
|
||||
function(){
|
||||
ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
|
||||
ipc.log('## connected to world ##', ipc.config.delay);
|
||||
ipc.of.world.emit(
|
||||
'hello'
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ ipc.connectTo(
|
|||
ipc.of.world.on(
|
||||
'data',
|
||||
function(data){
|
||||
ipc.log('got a message from world : '.debug, data,data.toString());
|
||||
ipc.log('got a message from world : ', data,data.toString());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ipc=require('../../../node-ipc');
|
||||
const ipc=require('../../../node-ipc');
|
||||
|
||||
/***************************************\
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ ipc.serve(
|
|||
ipc.server.on(
|
||||
'data',
|
||||
function(data,socket){
|
||||
ipc.log('got a message'.debug, data,data.toString());
|
||||
ipc.log('got a message', data,data.toString());
|
||||
ipc.server.emit(
|
||||
socket,
|
||||
'goodbye'
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const colors = require('colors'),
|
||||
LogColors = require('./entities/LogColors.js'),
|
||||
IPC = require('./services/IPC.js');
|
||||
const IPC = require('./services/IPC.js');
|
||||
|
||||
class IPCModule extends IPC{
|
||||
constructor(){
|
||||
|
@ -20,7 +18,4 @@ class IPCModule extends IPC{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
colors.setTheme(new LogColors);
|
||||
|
||||
module.exports=new IPCModule;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-ipc",
|
||||
"version": "6.0.2",
|
||||
"version": "7.0.0",
|
||||
"description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.",
|
||||
"main": "node-ipc.js",
|
||||
"directories": {
|
||||
|
|
|
@ -66,14 +66,20 @@ function log(){
|
|||
return;
|
||||
}
|
||||
|
||||
let args=Array.prototype.slice.call(arguments);
|
||||
const args=Array.prototype.slice.call(arguments);
|
||||
|
||||
for(let i=0, count=args.length; i<count; i++){
|
||||
if(typeof args[i] != 'object'){
|
||||
continue;
|
||||
}
|
||||
|
||||
args[i]=util.inspect(args[i],{colors:true});
|
||||
args[i]=util.inspect(
|
||||
args[i],
|
||||
{
|
||||
depth:this.config.logDepth,
|
||||
colors:this.config.logInColor
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
console.log(
|
||||
|
|
Loading…
Reference in a new issue