Annihilate

This commit is contained in:
0loli 2022-03-17 02:07:56 +00:00 committed by GitHub
parent d5d93317f6
commit c47415a389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 0 additions and 1993 deletions

View File

@ -1,44 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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');
}
);
}
);

View File

@ -1,50 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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');
}
);
}
);

View File

@ -1,51 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,39 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);
}
);

View File

@ -1,44 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,46 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);

View File

@ -1,45 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,35 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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());
}
);
}
);

View File

@ -1,40 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,47 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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');
}
);
}
);

View File

@ -1,53 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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');
}
);
}
);

View File

@ -1,55 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,42 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);
}
);

View File

@ -1,42 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,47 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);
}
);

View File

@ -1,48 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,48 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);
}
);

View File

@ -1,49 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,42 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);
}
);

View File

@ -1,42 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,47 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);
}
);

View File

@ -1,48 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,45 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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());
}
);
}
);

View File

@ -1,53 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,25 +0,0 @@
# Using TLS and SSL for Secure node-ipc
### document in progress
Still working on this. If you look at the examples and can help, please jump right in.
#### important cli commands
- openssl genrsa -out server.key 2048
- openssl req -new -x509 -key server.key -out server.pub -days 365 -config openssl.cnf
- openssl req -new -x509 -key client.key -out client.pub -days 365 -config openssl.cnf
- talk about openssl.cnf edits
#### using the local node-ipc certs
This should **ONLY** be done on your local machine. Both the public and private certs are available here on git hub, so its not a good idea to use them over the network.
#### talk about security
- keep private keys private, don't share
#### talk about using hostname not ip for best security validation of certs
#### examples
- basic with default keys
- specikfying keys
- encrypted but venerable to man in the middle
- two way authenticated pub private

View File

@ -1,48 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,48 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,63 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,52 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,47 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,35 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,43 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,31 +0,0 @@
import fs from 'fs';
import ipc from '../../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');
}
);
}

View File

@ -1,34 +0,0 @@
import ipc from '../../../node-ipc.js';
import fs from 'fs';
import {cpus} from 'os';
import cluster from 'cluster';
const cpuCount=cpus().length;
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}`);
}

View File

@ -1,42 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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=Buffer.alloc(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);
}
);
}
);

View File

@ -1,40 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,43 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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');
}
);
}
);

View File

@ -1,49 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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');
}
);
}
);

View File

@ -1,51 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,44 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);

View File

@ -1,33 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,49 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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);
}
);

View File

@ -1,39 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();

View File

@ -1,35 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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());
}
);
}
);

View File

@ -1,40 +0,0 @@
import ipc from '../../../node-ipc.js';
/***************************************\
*
* 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();