├── .gitattributes ├── .github └── workflows │ └── ci.yaml ├── .gitignore ├── .npmignore ├── CODE_OF_CONDUCT.md ├── README.md ├── dao ├── client.js └── socketServer.js ├── entities ├── Defaults.js └── EventParser.js ├── example ├── TCPSocket │ ├── Multi-Client-Broadcast │ │ ├── goodbye-client.js │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basic │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basicSync │ │ ├── hello-client.js │ │ └── world-server.js │ └── rawBuffer │ │ ├── hello-client.js │ │ └── world.server.js ├── TLSSocket │ ├── Multi-Client-Broadcast-basic │ │ ├── goodbye-client.js │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basic-local-only │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basic-more-secure │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basic-most-secure │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basic │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basicSync │ │ ├── hello-client.js │ │ └── world-server.js │ ├── rawBuffer-only-works-with-most-secure │ │ ├── hello-client.js │ │ └── world.server.js │ └── readme.md ├── UDPSocket │ ├── Multi-Client-Broadcast │ │ ├── goodbye-client.js │ │ ├── hello-client.js │ │ └── world-server.js │ ├── basic │ │ ├── hello-client.js │ │ └── world-server.js │ └── rawBuffer │ │ ├── hello-client.js │ │ └── world.server.js ├── clusterUnixSocket │ ├── cluster-client.js │ └── cluster-server.js ├── rawBuffer │ ├── hello-client.js │ └── world.server.js └── unixWindowsSocket │ ├── Multi-Client-Broadcast │ ├── goodbye-client.js │ ├── hello-client.js │ └── world-server.js │ ├── basic │ ├── hello-client.js │ └── world-server.js │ ├── basicSync │ ├── hello-client.js │ └── world-server.js │ └── rawBuffer │ ├── hello-client.js │ └── world.server.js ├── helpers └── delay.js ├── lcov.js ├── licence ├── local-node-ipc-certs ├── client.pub ├── openssl.cnf ├── private │ ├── client.key │ ├── dhparam.pem │ ├── oldclient.key │ ├── oldserver.key │ └── server.key └── server.pub ├── node-ipc.js ├── package-lock.json ├── package.json ├── services └── IPC.js └── test ├── CI.js ├── TCP ├── TCPClient.js ├── TCPServer.js ├── client.js └── server.js ├── UDP ├── UDP4Server.js ├── UDP6Server.js └── client.js └── unix ├── client.js ├── unixClient.js ├── unixServer.js └── unixServerSync.js /.gitattributes: -------------------------------------------------------------------------------- 1 | coverage/**/* linguist-generated=true 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | test: 11 | name: Test 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | os: 16 | - ubuntu-latest 17 | - macos-13 18 | - windows-latest 19 | node-version: 20 | - 14 21 | - 16 22 | - 17 23 | - 18 24 | - 19 25 | - 20 26 | - 21 27 | - 22 28 | steps: 29 | - uses: actions/checkout@v2 30 | - name: Use Node.js ${{ matrix.node-version }} 31 | uses: actions/setup-node@v1 32 | with: 33 | node-version: ${{ matrix.node-version }} 34 | - name: Install Dependencies 35 | run: npm ci --ignore-scripts 36 | - name: Run Tests 37 | run: npm test 38 | code-lint: 39 | name: Code Lint 40 | runs-on: ubuntu-latest 41 | steps: 42 | - uses: actions/checkout@v2 43 | - name: Use Node.js 16 44 | uses: actions/setup-node@v1 45 | with: 46 | node-version: 16 # LTS 47 | - name: Install Dependencies 48 | run: npm ci --ignore-scripts 49 | - name: Lockfile Lint 50 | run: | 51 | npm exec \ 52 | --no-install \ 53 | --package=lockfile-lint \ 54 | -- \ 55 | lockfile-lint \ 56 | --allowed-hosts=npm \ 57 | --path=./package-lock.json \ 58 | --validate-https \ 59 | --validate-package-names 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject/private/ 2 | /node_modules/ 3 | /nbproject 4 | npm-debug.log 5 | node-ipc.cjs 6 | /coverage/ 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | spec 2 | example 3 | coverage 4 | test -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | rifa@achrinza.com. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @achrinza/node-ipc 2 | 3 | > **NOTE:** This is a maintenance fork of `node-ipc` This is intended for 4 | > packages that directly or indirectly depend on `node-ipc` where maintainers 5 | > need a drop-in replacement. 6 | > 7 | > See https://github.com/achrinza/node-ipc/issues/1 for more details. 8 | 9 | [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md) 10 | 11 | _a nodejs module for local and remote Inter Process Communication_ with full support for Linux, Mac and Windows. It also supports all forms of socket communication from low level unix and windows sockets to UDP and secure TLS and TCP sockets. 12 | 13 | A great solution for complex multiprocess **Neural Networking** in Node.JS 14 | 15 | `npm install @achrinza/node-ipc` 16 | 17 | #### for node 0){ 177 | let message=new Message; 178 | message.load(data.shift()); 179 | 180 | // Only set the sock id if it is specified. 181 | if (message.data && message.data.id){ 182 | sock.id=message.data.id; 183 | } 184 | 185 | this.log('received event of : ',message.type,message.data); 186 | 187 | this.publish( 188 | message.type, 189 | message.data, 190 | sock 191 | ); 192 | } 193 | } 194 | 195 | function socketClosed(socket){ 196 | this.publish( 197 | 'close', 198 | socket 199 | ); 200 | } 201 | 202 | function serverCreated(socket) { 203 | this.sockets.push(socket); 204 | 205 | if(socket.setEncoding){ 206 | socket.setEncoding(this.config.encoding); 207 | } 208 | 209 | this.log('## socket connection to server detected ##'); 210 | socket.on( 211 | 'close', 212 | socketClosed.bind(this) 213 | ); 214 | 215 | socket.on( 216 | 'error', 217 | function(err){ 218 | this.log('server socket error',err); 219 | 220 | this.publish('error',err); 221 | }.bind(this) 222 | ); 223 | 224 | socket.on( 225 | 'data', 226 | gotData.bind(this,socket) 227 | ); 228 | 229 | socket.on( 230 | 'message', 231 | function(msg,rinfo) { 232 | if (!rinfo){ 233 | return; 234 | } 235 | 236 | this.log('Received UDP message from ', rinfo.address, rinfo.port); 237 | let data; 238 | 239 | if(this.config.rawSocket){ 240 | data=Buffer.from(msg,this.config.encoding); 241 | }else{ 242 | data=msg.toString(); 243 | } 244 | socket.emit('data',data,rinfo); 245 | }.bind(this) 246 | ); 247 | 248 | this.publish( 249 | 'connect', 250 | socket 251 | ); 252 | 253 | if(this.config.rawBuffer){ 254 | return; 255 | } 256 | } 257 | 258 | function startServer() { 259 | this.log( 260 | 'starting server on ',this.path, 261 | ((this.port)?`:${this.port}`:'') 262 | ); 263 | 264 | if(!this.udp4 && !this.udp6){ 265 | this.log('starting TLS server',this.config.tls); 266 | if(!this.config.tls){ 267 | this.server=net.createServer( 268 | serverCreated.bind(this) 269 | ); 270 | }else{ 271 | startTLSServer.bind(this)(); 272 | } 273 | }else{ 274 | this.server=dgram.createSocket( 275 | ((this.udp4)? 'udp4':'udp6') 276 | ); 277 | this.server.write=UDPWrite.bind(this); 278 | this.server.on( 279 | 'listening', 280 | function UDPServerStarted() { 281 | serverCreated.bind(this)(this.server); 282 | }.bind(this) 283 | ); 284 | } 285 | 286 | this.server.on( 287 | 'error', 288 | function(err){ 289 | this.log('server error',err); 290 | 291 | this.publish( 292 | 'error', 293 | err 294 | ); 295 | }.bind(this) 296 | ); 297 | 298 | this.server.maxConnections=this.config.maxConnections; 299 | 300 | if(!this.port){ 301 | this.log('starting server as', 'Unix || Windows Socket'); 302 | if (process.platform ==='win32'){ 303 | this.path = this.path.replace(/^\//, ''); 304 | this.path = this.path.replace(/\//g, '-'); 305 | this.path= `\\\\.\\pipe\\${this.path}`; 306 | } 307 | 308 | this.server.listen({ 309 | path: this.path, 310 | readableAll: this.config.readableAll, 311 | writableAll: this.config.writableAll 312 | }, this.onStart.bind(this)); 313 | 314 | return; 315 | } 316 | 317 | if(!this.udp4 && !this.udp6){ 318 | this.log('starting server as', (this.config.tls?'TLS':'TCP')); 319 | this.server.listen( 320 | this.port, 321 | this.path, 322 | this.onStart.bind(this) 323 | ); 324 | return; 325 | } 326 | 327 | this.log('starting server as',((this.udp4)? 'udp4':'udp6')); 328 | 329 | this.server.bind( 330 | this.port, 331 | this.path 332 | ); 333 | 334 | this.onStart( 335 | { 336 | address : this.path, 337 | port : this.port 338 | } 339 | ); 340 | } 341 | 342 | function startTLSServer(){ 343 | this.log('starting TLS server',this.config.tls); 344 | if(this.config.tls.private){ 345 | this.config.tls.key=fs.readFileSync(this.config.tls.private); 346 | }else{ 347 | this.config.tls.key=fs.readFileSync(`${__dirname}/../local-node-ipc-certs/private/server.key`); 348 | } 349 | if(this.config.tls.public){ 350 | this.config.tls.cert=fs.readFileSync(this.config.tls.public); 351 | }else{ 352 | this.config.tls.cert=fs.readFileSync(`${__dirname}/../local-node-ipc-certs/server.pub`); 353 | } 354 | if(this.config.tls.dhparam){ 355 | this.config.tls.dhparam=fs.readFileSync(this.config.tls.dhparam); 356 | } 357 | if(this.config.tls.trustedConnections){ 358 | if(typeof this.config.tls.trustedConnections === 'string'){ 359 | this.config.tls.trustedConnections=[this.config.tls.trustedConnections]; 360 | } 361 | this.config.tls.ca=[]; 362 | for(let i=0; i 0) { 55 | // getting the family of first network interface available 56 | IPType = networkInterfaces [ 57 | Object.keys( networkInterfaces )[0] 58 | ][0].family; 59 | } 60 | return IPType; 61 | } 62 | 63 | export { 64 | Defaults as default, 65 | Defaults 66 | } 67 | -------------------------------------------------------------------------------- /entities/EventParser.js: -------------------------------------------------------------------------------- 1 | 2 | import Defaults from './Defaults.js'; 3 | 4 | class Parser{ 5 | constructor(config){ 6 | if(!config){ 7 | config=new Defaults; 8 | } 9 | this.delimiter=config.delimiter; 10 | } 11 | 12 | format(message){ 13 | if(!message.data && message.data!==false && message.data!==0){ 14 | message.data={}; 15 | } 16 | if(message.data['_maxListeners']){ 17 | message.data={}; 18 | } 19 | 20 | message=message.JSON+this.delimiter; 21 | return message; 22 | } 23 | 24 | parse(data){ 25 | let events=data.split(this.delimiter); 26 | events.pop(); 27 | return events; 28 | } 29 | } 30 | 31 | export { 32 | Parser as default, 33 | Parser 34 | }; 35 | -------------------------------------------------------------------------------- /example/TCPSocket/Multi-Client-Broadcast/goodbye-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'goodbye'; 11 | ipc.config.retry= 1500; 12 | ipc.config.maxRetries= 10; 13 | 14 | ipc.connectToNet( 15 | 'world', 16 | function(){ 17 | ipc.of.world.on( 18 | 'connect', 19 | function(){ 20 | ipc.log('## connected to world ##', ipc.config.delay); 21 | ipc.of.world.emit( 22 | 'app.message', 23 | { 24 | id : ipc.config.id, 25 | message : 'goodbye' 26 | } 27 | ); 28 | } 29 | ); 30 | ipc.of.world.on( 31 | 'disconnect', 32 | function(){ 33 | ipc.log('disconnected from world'); 34 | } 35 | ); 36 | ipc.of.world.on( 37 | 'kill.connection', 38 | function(data){ 39 | ipc.log('world requested kill.connection'); 40 | ipc.disconnect('world'); 41 | } 42 | ); 43 | } 44 | ); 45 | -------------------------------------------------------------------------------- /example/TCPSocket/Multi-Client-Broadcast/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.maxRetries=10; 13 | 14 | ipc.connectToNet( 15 | 'world', 16 | function(){ 17 | ipc.of.world.on( 18 | 'connect', 19 | function(){ 20 | ipc.log('## connected to world ##', ipc.config.delay); 21 | ipc.of.world.emit( 22 | 'app.message', 23 | { 24 | id : ipc.config.id, 25 | message : 'hello' 26 | } 27 | ); 28 | } 29 | ); 30 | ipc.of.world.on( 31 | 'disconnect', 32 | function(){ 33 | ipc.log('disconnected from world'); 34 | } 35 | ); 36 | ipc.of.world.on( 37 | 'app.message', 38 | function(data){ 39 | ipc.log('got a message from world : ', data.message); 40 | } 41 | ); 42 | ipc.of.world.on( 43 | 'kill.connection', 44 | function(data){ 45 | ipc.log('world requested kill.connection'); 46 | ipc.disconnect('world'); 47 | } 48 | ); 49 | } 50 | ); 51 | -------------------------------------------------------------------------------- /example/TCPSocket/Multi-Client-Broadcast/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | 13 | var messages={ 14 | goodbye:false, 15 | hello:false 16 | }; 17 | 18 | ipc.serveNet( 19 | function(){ 20 | ipc.server.on( 21 | 'app.message', 22 | function(data,socket){ 23 | ipc.log('got a message from', (data.id), (data.message)); 24 | messages[data.id]=true; 25 | ipc.server.emit( 26 | socket, 27 | 'app.message', 28 | { 29 | id : ipc.config.id, 30 | message : data.message+' world!' 31 | } 32 | ); 33 | 34 | if(messages.hello && messages.goodbye){ 35 | ipc.log('got all required events, telling clients to kill connection'); 36 | ipc.server.broadcast( 37 | 'kill.connection', 38 | { 39 | id:ipc.config.id 40 | } 41 | ); 42 | } 43 | } 44 | ); 45 | } 46 | ); 47 | 48 | 49 | 50 | 51 | ipc.server.start(); 52 | -------------------------------------------------------------------------------- /example/TCPSocket/basic/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | 13 | ipc.connectToNet( 14 | 'world', 15 | function(){ 16 | ipc.of.world.on( 17 | 'connect', 18 | function(){ 19 | ipc.log('## connected to world ##', ipc.config.delay); 20 | ipc.of.world.emit( 21 | 'message', 22 | 'hello' 23 | ); 24 | } 25 | ); 26 | ipc.of.world.on( 27 | 'disconnect', 28 | function(){ 29 | ipc.log('disconnected from world'); 30 | } 31 | ); 32 | ipc.of.world.on( 33 | 'message', 34 | function(data){ 35 | ipc.log('got a message from world : ', data); 36 | } 37 | ); 38 | } 39 | ); 40 | -------------------------------------------------------------------------------- /example/TCPSocket/basic/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.maxConnections=1; 13 | 14 | ipc.serveNet( 15 | function(){ 16 | ipc.server.on( 17 | 'message', 18 | function(data,socket){ 19 | ipc.log('got a message : ', data); 20 | ipc.server.emit( 21 | socket, 22 | 'message', 23 | data+' world!' 24 | ); 25 | } 26 | ); 27 | 28 | ipc.server.on( 29 | 'socket.disconnected', 30 | function(data,socket){ 31 | console.log('DISCONNECTED\n\n',arguments); 32 | } 33 | ); 34 | } 35 | ); 36 | 37 | ipc.server.on( 38 | 'error', 39 | function(err){ 40 | ipc.log('Got an ERROR!',err); 41 | } 42 | ); 43 | 44 | ipc.server.start(); 45 | -------------------------------------------------------------------------------- /example/TCPSocket/basicSync/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.sync= true; 13 | 14 | ipc.connectToNet( 15 | 'world', 16 | function(){ 17 | ipc.of.world.on( 18 | 'connect', 19 | function(){ 20 | ipc.log('## connected to world ##', ipc.config.delay); 21 | 22 | //queue up a bunch of requests to be sent synchronously 23 | for(var i=0; i<10; i++){ 24 | ipc.of.world.emit( 25 | 'message', 26 | 'hello'+i 27 | ); 28 | } 29 | } 30 | ); 31 | ipc.of.world.on( 32 | 'disconnect', 33 | function(){ 34 | ipc.log('disconnected from world'); 35 | } 36 | ); 37 | ipc.of.world.on( 38 | 'message', 39 | function(data){ 40 | ipc.log('got a message from world : ', data,'\n\n'); 41 | } 42 | ); 43 | } 44 | ); 45 | 46 | console.log(ipc); 47 | -------------------------------------------------------------------------------- /example/TCPSocket/basicSync/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.sync = true; 13 | 14 | ipc.serveNet( 15 | function(){ 16 | ipc.server.on( 17 | 'message', 18 | function(data,socket){ 19 | ipc.log('got a message : ', data); 20 | //fake some synch procedural code 21 | setTimeout( 22 | function(){ 23 | ipc.server.emit( 24 | socket, 25 | 'message', 26 | data+' world!' 27 | ); 28 | }, 29 | 3000 30 | ); 31 | } 32 | ); 33 | 34 | ipc.server.on( 35 | 'socket.disconnected', 36 | function(data,socket){ 37 | console.log(arguments); 38 | } 39 | ); 40 | } 41 | ); 42 | 43 | 44 | 45 | ipc.server.start(); 46 | -------------------------------------------------------------------------------- /example/TCPSocket/rawBuffer/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | 15 | ipc.connectToNet( 16 | 'world', 17 | function(){ 18 | ipc.of.world.on( 19 | 'connect', 20 | function(){ 21 | ipc.log('## connected to world ##', ipc.config.delay); 22 | ipc.of.world.emit( 23 | 'hello' 24 | ); 25 | } 26 | ); 27 | 28 | ipc.of.world.on( 29 | 'data', 30 | function(data){ 31 | ipc.log('got a message from world : ', data,data.toString()); 32 | } 33 | ); 34 | } 35 | ); 36 | -------------------------------------------------------------------------------- /example/TCPSocket/rawBuffer/world.server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | 15 | ipc.serveNet( 16 | function(){ 17 | ipc.server.on( 18 | 'connect', 19 | function(socket){ 20 | ipc.server.emit( 21 | socket, 22 | 'hello' 23 | ); 24 | } 25 | ); 26 | 27 | ipc.server.on( 28 | 'data', 29 | function(data,socket){ 30 | ipc.log('got a message', data,data.toString()); 31 | ipc.server.emit( 32 | socket, 33 | 'goodbye' 34 | ); 35 | } 36 | ); 37 | } 38 | ); 39 | 40 | ipc.server.start(); 41 | -------------------------------------------------------------------------------- /example/TLSSocket/Multi-Client-Broadcast-basic/goodbye-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'goodbye'; 11 | ipc.config.retry= 1500; 12 | ipc.config.maxRetries= 10; 13 | ipc.config.tls={ 14 | rejectUnauthorized:false 15 | }; 16 | 17 | ipc.connectToNet( 18 | 'world', 19 | function(){ 20 | ipc.of.world.on( 21 | 'connect', 22 | function(){ 23 | ipc.log('## connected to world ##', ipc.config.delay); 24 | ipc.of.world.emit( 25 | 'app.message', 26 | { 27 | id : ipc.config.id, 28 | message : 'goodbye' 29 | } 30 | ); 31 | } 32 | ); 33 | ipc.of.world.on( 34 | 'disconnect', 35 | function(){ 36 | ipc.log('disconnected from world'); 37 | } 38 | ); 39 | ipc.of.world.on( 40 | 'kill.connection', 41 | function(data){ 42 | ipc.log('world requested kill.connection'); 43 | ipc.disconnect('world'); 44 | } 45 | ); 46 | } 47 | ); 48 | -------------------------------------------------------------------------------- /example/TLSSocket/Multi-Client-Broadcast-basic/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.maxRetries=10; 13 | ipc.config.tls={ 14 | rejectUnauthorized:false 15 | }; 16 | 17 | ipc.connectToNet( 18 | 'world', 19 | function(){ 20 | ipc.of.world.on( 21 | 'connect', 22 | function(){ 23 | ipc.log('## connected to world ##', ipc.config.delay); 24 | ipc.of.world.emit( 25 | 'app.message', 26 | { 27 | id : ipc.config.id, 28 | message : 'hello' 29 | } 30 | ); 31 | } 32 | ); 33 | ipc.of.world.on( 34 | 'disconnect', 35 | function(){ 36 | ipc.log('disconnected from world'); 37 | } 38 | ); 39 | ipc.of.world.on( 40 | 'app.message', 41 | function(data){ 42 | ipc.log('got a message from world : ', data.message); 43 | } 44 | ); 45 | ipc.of.world.on( 46 | 'kill.connection', 47 | function(data){ 48 | ipc.log('world requested kill.connection'); 49 | ipc.disconnect('world'); 50 | } 51 | ); 52 | } 53 | ); 54 | -------------------------------------------------------------------------------- /example/TLSSocket/Multi-Client-Broadcast-basic/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.tls={ 13 | public: __dirname+'/../../../local-node-ipc-certs/server.pub', 14 | private: __dirname+'/../../../local-node-ipc-certs/private/server.key' 15 | }; 16 | 17 | var messages={ 18 | goodbye:false, 19 | hello:false 20 | }; 21 | 22 | ipc.serveNet( 23 | function(){ 24 | ipc.server.on( 25 | 'app.message', 26 | function(data,socket){ 27 | ipc.log('got a message from', (data.id), (data.message)); 28 | messages[data.id]=true; 29 | ipc.server.emit( 30 | socket, 31 | 'app.message', 32 | { 33 | id : ipc.config.id, 34 | message : data.message+' world!' 35 | } 36 | ); 37 | 38 | if(messages.hello && messages.goodbye){ 39 | ipc.log('got all required events, telling clients to kill connection'); 40 | ipc.server.broadcast( 41 | 'kill.connection', 42 | { 43 | id:ipc.config.id 44 | } 45 | ); 46 | } 47 | } 48 | ); 49 | } 50 | ); 51 | 52 | 53 | 54 | 55 | ipc.server.start(); 56 | -------------------------------------------------------------------------------- /example/TLSSocket/basic-local-only/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.tls={ 13 | rejectUnauthorized:false 14 | }; 15 | 16 | ipc.connectToNet( 17 | 'world', 18 | function(){ 19 | ipc.of.world.on( 20 | 'connect', 21 | function(){ 22 | ipc.log('## connected to world ##', ipc.config.delay); 23 | ipc.of.world.emit( 24 | 'message', 25 | 'hello' 26 | ); 27 | } 28 | ); 29 | ipc.of.world.on( 30 | 'disconnect', 31 | function(){ 32 | ipc.log('disconnected from world'); 33 | } 34 | ); 35 | ipc.of.world.on( 36 | 'message', 37 | function(data){ 38 | ipc.log('got a message from world : ', data); 39 | } 40 | ); 41 | } 42 | ); 43 | -------------------------------------------------------------------------------- /example/TLSSocket/basic-local-only/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | //node-ipc will default to its local certs 13 | ipc.config.tls={ 14 | rejectUnauthorized:false 15 | }; 16 | 17 | ipc.serveNet( 18 | function(){ 19 | ipc.server.on( 20 | 'message', 21 | function(data,socket){ 22 | ipc.log('got a message : ', data); 23 | ipc.server.emit( 24 | socket, 25 | 'message', 26 | data+' world!' 27 | ); 28 | } 29 | ); 30 | 31 | ipc.server.on( 32 | 'socket.disconnected', 33 | function(data,socket){ 34 | console.log(arguments); 35 | } 36 | ); 37 | } 38 | ); 39 | 40 | 41 | 42 | ipc.server.start(); 43 | -------------------------------------------------------------------------------- /example/TLSSocket/basic-more-secure/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.tls={ 13 | private: __dirname+'/../../../local-node-ipc-certs/private/client.key', 14 | public: __dirname+'/../../../local-node-ipc-certs/client.pub', 15 | rejectUnauthorized:false, 16 | trustedConnections: [ 17 | __dirname+'/../../../local-node-ipc-certs/server.pub' 18 | ] 19 | }; 20 | 21 | ipc.connectToNet( 22 | 'world', 23 | function(){ 24 | ipc.of.world.on( 25 | 'connect', 26 | function(){ 27 | ipc.log('## connected to world ##', ipc.config.delay); 28 | ipc.of.world.emit( 29 | 'message', 30 | 'hello' 31 | ); 32 | } 33 | ); 34 | ipc.of.world.on( 35 | 'disconnect', 36 | function(){ 37 | ipc.log('disconnected from world'); 38 | } 39 | ); 40 | ipc.of.world.on( 41 | 'message', 42 | function(data){ 43 | ipc.log('got a message from world : ', data); 44 | } 45 | ); 46 | } 47 | ); 48 | -------------------------------------------------------------------------------- /example/TLSSocket/basic-more-secure/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.tls={ 13 | public: __dirname+'/../../../local-node-ipc-certs/server.pub', 14 | private: __dirname+'/../../../local-node-ipc-certs/private/server.key', 15 | dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem', 16 | requestCert: true, 17 | rejectUnauthorized:false, 18 | trustedConnections: [ 19 | __dirname+'/../../../local-node-ipc-certs/client.pub' 20 | ] 21 | }; 22 | 23 | ipc.serveNet( 24 | function(){ 25 | ipc.server.on( 26 | 'message', 27 | function(data,socket){ 28 | ipc.log('got a message : ', data); 29 | ipc.server.emit( 30 | socket, 31 | 'message', 32 | data+' world!' 33 | ); 34 | } 35 | ); 36 | 37 | ipc.server.on( 38 | 'socket.disconnected', 39 | function(data,socket){ 40 | console.log(arguments); 41 | } 42 | ); 43 | } 44 | ); 45 | 46 | 47 | 48 | ipc.server.start(); 49 | -------------------------------------------------------------------------------- /example/TLSSocket/basic-most-secure/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.networkHost='localhost'; 13 | ipc.config.tls={ 14 | private: __dirname+'/../../../local-node-ipc-certs/private/client.key', 15 | public: __dirname+'/../../../local-node-ipc-certs/client.pub', 16 | rejectUnauthorized:true, 17 | trustedConnections: [ 18 | __dirname+'/../../../local-node-ipc-certs/server.pub' 19 | ] 20 | }; 21 | 22 | ipc.connectToNet( 23 | 'world', 24 | function(){ 25 | ipc.of.world.on( 26 | 'connect', 27 | function(){ 28 | ipc.log('## connected to world ##', ipc.config.delay); 29 | ipc.of.world.emit( 30 | 'message', 31 | 'hello' 32 | ); 33 | } 34 | ); 35 | ipc.of.world.on( 36 | 'disconnect', 37 | function(){ 38 | ipc.log('disconnected from world'); 39 | } 40 | ); 41 | ipc.of.world.on( 42 | 'message', 43 | function(data){ 44 | ipc.log('got a message from world : ', data); 45 | } 46 | ); 47 | } 48 | ); 49 | -------------------------------------------------------------------------------- /example/TLSSocket/basic-most-secure/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.networkHost='localhost'; 13 | ipc.config.tls={ 14 | public: __dirname+'/../../../local-node-ipc-certs/server.pub', 15 | private: __dirname+'/../../../local-node-ipc-certs/private/server.key', 16 | dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem', 17 | requestCert: true, 18 | rejectUnauthorized:true, 19 | trustedConnections: [ 20 | __dirname+'/../../../local-node-ipc-certs/client.pub' 21 | ] 22 | }; 23 | 24 | ipc.serveNet( 25 | function(){ 26 | ipc.server.on( 27 | 'message', 28 | function(data,socket){ 29 | ipc.log('got a message : ', data); 30 | ipc.server.emit( 31 | socket, 32 | 'message', 33 | data+' world!' 34 | ); 35 | } 36 | ); 37 | 38 | ipc.server.on( 39 | 'socket.disconnected', 40 | function(data,socket){ 41 | console.log(arguments); 42 | } 43 | ); 44 | } 45 | ); 46 | 47 | 48 | 49 | ipc.server.start(); 50 | -------------------------------------------------------------------------------- /example/TLSSocket/basic/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.tls={ 13 | rejectUnauthorized:false 14 | }; 15 | 16 | ipc.connectToNet( 17 | 'world', 18 | function(){ 19 | ipc.of.world.on( 20 | 'connect', 21 | function(){ 22 | ipc.log('## connected to world ##', ipc.config.delay); 23 | ipc.of.world.emit( 24 | 'message', 25 | 'hello' 26 | ); 27 | } 28 | ); 29 | ipc.of.world.on( 30 | 'disconnect', 31 | function(){ 32 | ipc.log('disconnected from world'); 33 | } 34 | ); 35 | ipc.of.world.on( 36 | 'message', 37 | function(data){ 38 | ipc.log('got a message from world : ', data); 39 | } 40 | ); 41 | } 42 | ); 43 | -------------------------------------------------------------------------------- /example/TLSSocket/basic/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.tls={ 13 | public: __dirname+'/../../../local-node-ipc-certs/server.pub', 14 | private: __dirname+'/../../../local-node-ipc-certs/private/server.key' 15 | }; 16 | 17 | ipc.serveNet( 18 | function(){ 19 | ipc.server.on( 20 | 'message', 21 | function(data,socket){ 22 | ipc.log('got a message : ', data); 23 | ipc.server.emit( 24 | socket, 25 | 'message', 26 | data+' world!' 27 | ); 28 | } 29 | ); 30 | 31 | ipc.server.on( 32 | 'socket.disconnected', 33 | function(data,socket){ 34 | console.log(arguments); 35 | } 36 | ); 37 | } 38 | ); 39 | 40 | 41 | 42 | ipc.server.start(); 43 | -------------------------------------------------------------------------------- /example/TLSSocket/basicSync/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.sync= true; 13 | ipc.config.tls={ 14 | rejectUnauthorized:false 15 | }; 16 | 17 | ipc.connectToNet( 18 | 'world', 19 | function(){ 20 | ipc.of.world.on( 21 | 'connect', 22 | function(){ 23 | ipc.log('## connected to world ##', ipc.config.delay); 24 | 25 | //queue up a bunch of requests to be sent synchronously 26 | for(var i=0; i<10; i++){ 27 | ipc.of.world.emit( 28 | 'message', 29 | 'hello'+i 30 | ); 31 | } 32 | } 33 | ); 34 | ipc.of.world.on( 35 | 'disconnect', 36 | function(){ 37 | ipc.log('disconnected from world'); 38 | } 39 | ); 40 | ipc.of.world.on( 41 | 'message', 42 | function(data){ 43 | ipc.log('got a message from world : ', data); 44 | } 45 | ); 46 | } 47 | ); 48 | -------------------------------------------------------------------------------- /example/TLSSocket/basicSync/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.sync= true; 13 | ipc.config.tls={ 14 | public: __dirname+'/../../../local-node-ipc-certs/server.pub', 15 | private: __dirname+'/../../../local-node-ipc-certs/private/server.key' 16 | }; 17 | 18 | ipc.serveNet( 19 | function(){ 20 | ipc.server.on( 21 | 'message', 22 | function(data,socket){ 23 | ipc.log('got a message : ', data); 24 | setTimeout( 25 | function(){ 26 | ipc.server.emit( 27 | socket, 28 | 'message', 29 | data+' world!' 30 | ); 31 | }, 32 | 3000 33 | ); 34 | } 35 | ); 36 | 37 | ipc.server.on( 38 | 'socket.disconnected', 39 | function(data,socket){ 40 | console.log(arguments); 41 | } 42 | ); 43 | } 44 | ); 45 | 46 | 47 | 48 | ipc.server.start(); 49 | -------------------------------------------------------------------------------- /example/TLSSocket/rawBuffer-only-works-with-most-secure/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | ipc.config.networkHost='localhost'; 15 | 16 | ipc.config.tls={ 17 | private: __dirname+'/../../../local-node-ipc-certs/private/client.key', 18 | public: __dirname+'/../../../local-node-ipc-certs/client.pub', 19 | rejectUnauthorized:true, 20 | trustedConnections: [ 21 | __dirname+'/../../../local-node-ipc-certs/server.pub' 22 | ] 23 | }; 24 | 25 | ipc.connectToNet( 26 | 'world', 27 | function(){ 28 | ipc.of.world.on( 29 | 'connect', 30 | function(){ 31 | ipc.log('## connected to world ##', ipc.config.delay); 32 | ipc.of.world.emit( 33 | 'hello' 34 | ); 35 | } 36 | ); 37 | 38 | ipc.of.world.on( 39 | 'data', 40 | function(data){ 41 | ipc.log('got a message from world : ', data,data.toString()); 42 | } 43 | ); 44 | } 45 | ); 46 | -------------------------------------------------------------------------------- /example/TLSSocket/rawBuffer-only-works-with-most-secure/world.server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | ipc.config.networkHost='localhost'; 15 | 16 | ipc.config.tls={ 17 | public: __dirname+'/../../../local-node-ipc-certs/server.pub', 18 | private: __dirname+'/../../../local-node-ipc-certs/private/server.key', 19 | dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem', 20 | requestCert: true, 21 | rejectUnauthorized:true, 22 | trustedConnections: [ 23 | __dirname+'/../../../local-node-ipc-certs/client.pub' 24 | ] 25 | }; 26 | 27 | ipc.serveNet( 28 | function(){ 29 | ipc.server.on( 30 | 'connect', 31 | function(socket){ 32 | console.log('connection detected'); 33 | ipc.server.emit( 34 | socket, 35 | 'hello' 36 | ); 37 | } 38 | ); 39 | 40 | ipc.server.on( 41 | 'data', 42 | function(data,socket){ 43 | ipc.log('got a message', data,data.toString()); 44 | ipc.server.emit( 45 | socket, 46 | 'goodbye' 47 | ); 48 | } 49 | ); 50 | } 51 | ); 52 | 53 | ipc.server.start(); 54 | -------------------------------------------------------------------------------- /example/TLSSocket/readme.md: -------------------------------------------------------------------------------- 1 | # Using TLS and SSL for Secure node-ipc 2 | 3 | ### document in progress 4 | Still working on this. If you look at the examples and can help, please jump right in. 5 | 6 | #### important cli commands 7 | - openssl genrsa -out server.key 2048 8 | - openssl req -new -x509 -key server.key -out server.pub -days 365 -config openssl.cnf 9 | - openssl req -new -x509 -key client.key -out client.pub -days 365 -config openssl.cnf 10 | - talk about openssl.cnf edits 11 | 12 | #### using the local node-ipc certs 13 | 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. 14 | 15 | #### talk about security 16 | - keep private keys private, don't share 17 | 18 | #### talk about using hostname not ip for best security validation of certs 19 | 20 | 21 | #### examples 22 | - basic with default keys 23 | - specikfying keys 24 | - encrypted but venerable to man in the middle 25 | - two way authenticated pub private 26 | -------------------------------------------------------------------------------- /example/UDPSocket/Multi-Client-Broadcast/goodbye-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * Since there is no client relationship 6 | * with UDP sockets sockets are not kept 7 | * open. 8 | * 9 | * This means the order sockets are opened 10 | * is important. 11 | * 12 | * Start World first. Then you can start 13 | * hello or goodbye in any order you 14 | * choose. 15 | * 16 | * *************************************/ 17 | 18 | ipc.config.id = 'goodbye'; 19 | ipc.config.retry= 1500; 20 | 21 | ipc.serveNet( 22 | 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. 23 | 'udp4', 24 | function(){ 25 | ipc.server.on( 26 | 'message', 27 | function(data){ 28 | ipc.log('got Data'); 29 | ipc.log('got a message from ', data.id ,' : ', data.message); 30 | } 31 | ); 32 | ipc.server.emit( 33 | { 34 | address : 'localhost', 35 | port : ipc.config.networkPort 36 | }, 37 | 'message', 38 | { 39 | id : ipc.config.id, 40 | message : 'Goodbye' 41 | } 42 | ); 43 | } 44 | ); 45 | 46 | 47 | 48 | ipc.server.start(); 49 | -------------------------------------------------------------------------------- /example/UDPSocket/Multi-Client-Broadcast/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * Since there is no client relationship 6 | * with UDP sockets sockets are not kept 7 | * open. 8 | * 9 | * This means the order sockets are opened 10 | * is important. 11 | * 12 | * Start World first. Then you can start 13 | * hello or goodbye in any order you 14 | * choose. 15 | * 16 | * *************************************/ 17 | 18 | ipc.config.id = 'hello'; 19 | ipc.config.retry= 1500; 20 | 21 | ipc.serveNet( 22 | 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. 23 | 'udp4', 24 | function(){ 25 | ipc.server.on( 26 | 'message', 27 | function(data){ 28 | ipc.log('got Data'); 29 | ipc.log('got a message from ', data.id ,' : ', data.message); 30 | } 31 | ); 32 | ipc.server.emit( 33 | { 34 | address : 'localhost', 35 | port : ipc.config.networkPort 36 | }, 37 | 'message', 38 | { 39 | id : ipc.config.id, 40 | message : 'Hello' 41 | } 42 | ); 43 | } 44 | ); 45 | 46 | 47 | 48 | ipc.server.start(); 49 | -------------------------------------------------------------------------------- /example/UDPSocket/Multi-Client-Broadcast/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * Since there is no client relationship 6 | * with UDP sockets sockets are not kept 7 | * open. 8 | * 9 | * This means the order sockets are opened 10 | * is important. 11 | * 12 | * Start World first. Then you can start 13 | * hello or goodbye in any order you 14 | * choose. 15 | * 16 | ***************************************/ 17 | 18 | ipc.config.id = 'world'; 19 | ipc.config.retry= 1500; 20 | 21 | var messages={ 22 | goodbye:false, 23 | hello:false 24 | }; 25 | 26 | ipc.serveNet( 27 | 'udp4', 28 | function(){ 29 | console.log(123); 30 | ipc.server.on( 31 | 'message', 32 | function(data,socket){ 33 | ipc.log('got a message from ', data.id ,' : ', data.message); 34 | messages[data.id]=true; 35 | ipc.server.emit( 36 | socket, 37 | 'message', 38 | { 39 | id : ipc.config.id, 40 | message : data.message+' world!' 41 | } 42 | ); 43 | 44 | if(messages.hello && messages.goodbye){ 45 | ipc.log('got all required events, telling evryone how muchg I am loved!'); 46 | ipc.server.broadcast( 47 | 'message', 48 | { 49 | id : ipc.config.id, 50 | message : 'Everybody Loves The World! Got messages from hello and goodbye!' 51 | } 52 | ); 53 | } 54 | } 55 | ); 56 | 57 | console.log(ipc.server); 58 | } 59 | ); 60 | 61 | 62 | 63 | ipc.server.start(); 64 | -------------------------------------------------------------------------------- /example/UDPSocket/basic/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * UDP Client is really a UDP server 6 | * 7 | * Dedicated UDP sockets on the same 8 | * machine can not be bound to in the 9 | * traditional client/server method 10 | * 11 | * Every UDP socket is it's own UDP server 12 | * And so must have a unique port on its 13 | * machine, unlike TCP or Unix Sockts 14 | * which can share on the same machine. 15 | * 16 | * Since there is no open client server 17 | * relationship, you should start world 18 | * first and then hello. 19 | * 20 | * *************************************/ 21 | 22 | ipc.config.id = 'hello'; 23 | ipc.config.retry= 1500; 24 | 25 | ipc.serveNet( 26 | 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. 27 | 'udp4', 28 | function(){ 29 | ipc.server.on( 30 | 'message', 31 | function(data){ 32 | ipc.log('got Data'); 33 | ipc.log('got a message from ', data.id ,' : ', data.message); 34 | } 35 | ); 36 | ipc.server.emit( 37 | { 38 | address : 'localhost', 39 | port : ipc.config.networkPort 40 | }, 41 | 'message', 42 | { 43 | id : ipc.config.id, 44 | message : 'Hello' 45 | } 46 | ); 47 | } 48 | ); 49 | 50 | 51 | 52 | ipc.server.start(); 53 | -------------------------------------------------------------------------------- /example/UDPSocket/basic/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * UDP Client is really a UDP server 6 | * 7 | * Dedicated UDP sockets on the same 8 | * machine can not be bound to in the 9 | * traditional client/server method 10 | * 11 | * Every UDP socket is it's own UDP server 12 | * And so must have a unique port on its 13 | * machine, unlike TCP or Unix Sockts 14 | * which can share on the same machine. 15 | * 16 | * Since there is no open client server 17 | * relationship, you should start world 18 | * first and then hello. 19 | * 20 | ***************************************/ 21 | 22 | ipc.config.id = 'world'; 23 | ipc.config.retry= 1500; 24 | 25 | ipc.serveNet( 26 | 'udp4', 27 | function(){ 28 | ipc.server.on( 29 | 'message', 30 | function(data,socket){ 31 | ipc.log('got a message from ', data.id ,' : ', data.message); 32 | ipc.server.emit( 33 | socket, 34 | 'message', 35 | { 36 | id : ipc.config.id, 37 | message : data.message+' world!' 38 | } 39 | ); 40 | } 41 | ); 42 | } 43 | ); 44 | 45 | 46 | 47 | ipc.server.start(); 48 | -------------------------------------------------------------------------------- /example/UDPSocket/rawBuffer/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | 15 | ipc.serveNet( 16 | 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. 17 | 'udp4', 18 | function(){ 19 | ipc.server.on( 20 | 'data', 21 | function(data){ 22 | ipc.log('got a message from world ', data, data.toString()); 23 | } 24 | ); 25 | ipc.server.emit( 26 | { 27 | address : 'localhost', 28 | port : ipc.config.networkPort 29 | }, 30 | 'hello' 31 | ); 32 | } 33 | ); 34 | 35 | ipc.server.start(); 36 | -------------------------------------------------------------------------------- /example/UDPSocket/rawBuffer/world.server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * UDP Client is really a UDP server 6 | * 7 | * Dedicated UDP sockets on the same 8 | * machine can not be bound to in the 9 | * traditional client/server method 10 | * 11 | * Every UDP socket is it's own UDP server 12 | * And so must have a unique port on its 13 | * machine, unlike TCP or Unix Sockts 14 | * which can share on the same machine. 15 | * 16 | * Since there is no open client server 17 | * relationship, you should start world 18 | * first and then hello. 19 | * 20 | ***************************************/ 21 | 22 | ipc.config.id = 'world'; 23 | ipc.config.retry= 1500; 24 | ipc.config.rawBuffer=true; 25 | ipc.config.encoding='ascii'; 26 | 27 | ipc.serveNet( 28 | 'udp4', 29 | function(){ 30 | ipc.server.on( 31 | 'data', 32 | function(data,socket){ 33 | ipc.log('got a message', data,data.toString()); 34 | ipc.server.emit( 35 | socket, 36 | 'goodbye' 37 | ); 38 | } 39 | ); 40 | } 41 | ); 42 | 43 | ipc.server.start(); 44 | -------------------------------------------------------------------------------- /example/clusterUnixSocket/cluster-client.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import ipc from '../../node-ipc'; 3 | 4 | const socketPath = '/tmp/ipc.sock'; 5 | 6 | //loop forever so you can see the pid of the cluster sever change in the logs 7 | setInterval( 8 | function() { 9 | ipc.connectTo( 10 | 'world', 11 | socketPath, 12 | connecting 13 | ); 14 | }, 15 | 2000 16 | ); 17 | 18 | function connecting(socket) { 19 | ipc.of.world.on( 20 | 'connect', 21 | function() { 22 | ipc.of.world.emit( 23 | 'currentDate', 24 | { 25 | message: new Date().toISOString() 26 | } 27 | ); 28 | ipc.disconnect('world'); 29 | } 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /example/clusterUnixSocket/cluster-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | import fs from 'fs'; 3 | import {cpus} from 'os'; 4 | import cluster from 'cluster'; 5 | 6 | const cpuCount=cpus().length; 7 | const socketPath = '/tmp/ipc.sock'; 8 | 9 | ipc.config.unlink = false; 10 | 11 | if (cluster.isMaster) { 12 | if (fs.existsSync(socketPath)) { 13 | fs.unlinkSync(socketPath); 14 | } 15 | 16 | for (let i = 0; i < cpuCount; i++) { 17 | cluster.fork(); 18 | } 19 | }else{ 20 | ipc.serve( 21 | socketPath, 22 | function() { 23 | ipc.server.on( 24 | 'currentDate', 25 | function(data,socket) { 26 | console.log(`pid ${process.pid} got: `, data); 27 | } 28 | ); 29 | } 30 | ); 31 | 32 | ipc.server.start(); 33 | console.log(`pid ${process.pid} listening on ${socketPath}`); 34 | } 35 | -------------------------------------------------------------------------------- /example/rawBuffer/hello-client.js: -------------------------------------------------------------------------------- 1 | 2 | import ipc from '../../../node-ipc.js'; 3 | 4 | /***************************************\ 5 | * 6 | * You should start both hello and world 7 | * then you will see them communicating. 8 | * 9 | * *************************************/ 10 | 11 | ipc.config.id = 'hello'; 12 | ipc.config.retry= 1500; 13 | ipc.config.rawBuffer=true; 14 | ipc.config.encoding='hex'; 15 | 16 | ipc.connectTo( 17 | 'world', 18 | function(){ 19 | ipc.of.world.on( 20 | 'connect', 21 | function(){ 22 | //make a 6 byte buffer for example 23 | const myBuffer=Buffer.alloc(6).fill(0); 24 | 25 | myBuffer.writeUInt16BE(0x02,0); 26 | myBuffer.writeUInt32BE(0xffeecc,2); 27 | 28 | ipc.log('## connected to world ##', ipc.config.delay); 29 | ipc.of.world.emit( 30 | myBuffer 31 | ); 32 | } 33 | ); 34 | 35 | ipc.of.world.on( 36 | 'data', 37 | function(data){ 38 | ipc.log('got a message from world : ', data); 39 | } 40 | ); 41 | } 42 | ); 43 | -------------------------------------------------------------------------------- /example/rawBuffer/world.server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='hex'; 14 | 15 | ipc.serve( 16 | function(){ 17 | ipc.server.on( 18 | 'connect', 19 | function(socket){ 20 | ipc.server.emit( 21 | socket, 22 | [0xaa] 23 | ); 24 | } 25 | ); 26 | 27 | ipc.server.on( 28 | 'data', 29 | function(data,socket){ 30 | ipc.log('got a message', data); 31 | ipc.server.emit( 32 | socket, 33 | [0x0d,0xee] 34 | ); 35 | } 36 | ); 37 | } 38 | ); 39 | 40 | ipc.server.start(); 41 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/Multi-Client-Broadcast/goodbye-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'goodbye'; 11 | ipc.config.retry= 1500; 12 | 13 | ipc.connectTo( 14 | 'world', 15 | function(){ 16 | ipc.of.world.on( 17 | 'connect', 18 | function(){ 19 | ipc.log('## connected to world ##', ipc.config.delay); 20 | ipc.of.world.emit( 21 | 'app.message', 22 | { 23 | id : ipc.config.id, 24 | message : 'goodbye' 25 | } 26 | ); 27 | } 28 | ); 29 | ipc.of.world.on( 30 | 'disconnect', 31 | function(){ 32 | ipc.log('disconnected from world'); 33 | } 34 | ); 35 | ipc.of.world.on( 36 | 'kill.connection', 37 | function(data){ 38 | ipc.log('world requested kill.connection'); 39 | ipc.disconnect('world'); 40 | } 41 | ); 42 | } 43 | ); 44 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/Multi-Client-Broadcast/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | 13 | ipc.connectTo( 14 | 'world', 15 | function(){ 16 | ipc.of.world.on( 17 | 'connect', 18 | function(){ 19 | ipc.log('## connected to world ##', ipc.config.delay); 20 | ipc.of.world.emit( 21 | 'app.message', 22 | { 23 | id : ipc.config.id, 24 | message : 'hello' 25 | } 26 | ); 27 | } 28 | ); 29 | ipc.of.world.on( 30 | 'disconnect', 31 | function(){ 32 | ipc.log('disconnected from world'); 33 | } 34 | ); 35 | ipc.of.world.on( 36 | 'app.message', 37 | function(data){ 38 | ipc.log('got a message from world : ', data); 39 | } 40 | ); 41 | ipc.of.world.on( 42 | 'kill.connection', 43 | function(data){ 44 | ipc.log('world requested kill.connection'); 45 | ipc.disconnect('world'); 46 | } 47 | ); 48 | } 49 | ); 50 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/Multi-Client-Broadcast/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | 13 | var messages={ 14 | goodbye:false, 15 | hello:false 16 | }; 17 | 18 | ipc.serve( 19 | function(){ 20 | ipc.server.on( 21 | 'app.message', 22 | function(data,socket){ 23 | ipc.log('got a message from', (data.id), (data.message)); 24 | messages[data.id]=true; 25 | ipc.server.emit( 26 | socket, 27 | 'app.message', 28 | { 29 | id : ipc.config.id, 30 | message : data.message+' world!' 31 | } 32 | ); 33 | 34 | if(messages.hello && messages.goodbye){ 35 | ipc.log('got all required events, telling clients to kill connection'); 36 | ipc.server.broadcast( 37 | 'kill.connection', 38 | { 39 | id:ipc.config.id 40 | } 41 | ); 42 | } 43 | } 44 | ); 45 | } 46 | ); 47 | 48 | 49 | 50 | 51 | ipc.server.start(); 52 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/basic/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry = 1000; 12 | 13 | ipc.connectTo( 14 | 'world', 15 | function(){ 16 | ipc.of.world.on( 17 | 'connect', 18 | function(){ 19 | ipc.log('## connected to world ##', ipc.config.delay); 20 | ipc.of.world.emit( 21 | 'app.message', 22 | { 23 | id : ipc.config.id, 24 | message : 'hello' 25 | } 26 | ); 27 | } 28 | ); 29 | ipc.of.world.on( 30 | 'disconnect', 31 | function(){ 32 | ipc.log('disconnected from world'); 33 | } 34 | ); 35 | ipc.of.world.on( 36 | 'app.message', 37 | function(data){ 38 | ipc.log('got a message from world : ', data); 39 | } 40 | ); 41 | 42 | console.log(ipc.of.world.destroy); 43 | } 44 | ); 45 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/basic/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | 13 | ipc.serve( 14 | function(){ 15 | ipc.server.on( 16 | 'app.message', 17 | function(data,socket){ 18 | ipc.server.emit( 19 | socket, 20 | 'app.message', 21 | { 22 | id : ipc.config.id, 23 | message : data.message+' world!' 24 | } 25 | ); 26 | } 27 | ); 28 | } 29 | ); 30 | 31 | 32 | 33 | ipc.server.start(); 34 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/basicSync/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry = 1000; 12 | ipc.config.sync= true; 13 | 14 | ipc.connectTo( 15 | 'world', 16 | function(){ 17 | ipc.of.world.on( 18 | 'connect', 19 | function(){ 20 | ipc.log('## connected to world ##', ipc.config.delay); 21 | 22 | //queue up a bunch of requests to be sent synchronously 23 | for(var i=0; i<10; i++){ 24 | ipc.of.world.emit( 25 | 'app.message', 26 | { 27 | id : ipc.config.id, 28 | message : 'hello'+i 29 | } 30 | ); 31 | } 32 | } 33 | ); 34 | ipc.of.world.on( 35 | 'disconnect', 36 | function(){ 37 | ipc.log('disconnected from world'); 38 | } 39 | ); 40 | ipc.of.world.on( 41 | 'app.message', 42 | function(data){ 43 | ipc.log('got a message from world : ', data); 44 | } 45 | ); 46 | 47 | console.log(ipc.of.world.destroy); 48 | } 49 | ); 50 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/basicSync/world-server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.sync= true; 13 | 14 | ipc.serve( 15 | function(){ 16 | ipc.server.on( 17 | 'app.message', 18 | function(data,socket){ 19 | setTimeout( 20 | function(){ 21 | ipc.server.emit( 22 | socket, 23 | 'app.message', 24 | { 25 | id : ipc.config.id, 26 | message : data.message+' world!' 27 | } 28 | ); 29 | }, 30 | 2000 31 | ); 32 | } 33 | ); 34 | } 35 | ); 36 | 37 | 38 | 39 | ipc.server.start(); 40 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/rawBuffer/hello-client.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'hello'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | 15 | ipc.connectTo( 16 | 'world', 17 | function(){ 18 | ipc.of.world.on( 19 | 'connect', 20 | function(){ 21 | ipc.log('## connected to world ##', ipc.config.delay); 22 | ipc.of.world.emit( 23 | 'hello' 24 | ); 25 | } 26 | ); 27 | 28 | ipc.of.world.on( 29 | 'data', 30 | function(data){ 31 | ipc.log('got a message from world : ', data,data.toString()); 32 | } 33 | ); 34 | } 35 | ); 36 | -------------------------------------------------------------------------------- /example/unixWindowsSocket/rawBuffer/world.server.js: -------------------------------------------------------------------------------- 1 | import ipc from '../../../node-ipc.js'; 2 | 3 | /***************************************\ 4 | * 5 | * You should start both hello and world 6 | * then you will see them communicating. 7 | * 8 | * *************************************/ 9 | 10 | ipc.config.id = 'world'; 11 | ipc.config.retry= 1500; 12 | ipc.config.rawBuffer=true; 13 | ipc.config.encoding='ascii'; 14 | 15 | ipc.serve( 16 | function(){ 17 | ipc.server.on( 18 | 'connect', 19 | function(socket){ 20 | ipc.server.emit( 21 | socket, 22 | 'hello' 23 | ); 24 | } 25 | ); 26 | 27 | ipc.server.on( 28 | 'data', 29 | function(data,socket){ 30 | ipc.log('got a message', data,data.toString()); 31 | ipc.server.emit( 32 | socket, 33 | 'goodbye' 34 | ); 35 | } 36 | ); 37 | } 38 | ); 39 | 40 | ipc.server.start(); 41 | -------------------------------------------------------------------------------- /helpers/delay.js: -------------------------------------------------------------------------------- 1 | async function delay(ms=100) { 2 | return new Promise( 3 | resolve => { 4 | setTimeout(resolve, ms); 5 | } 6 | ); 7 | } 8 | 9 | export { 10 | delay as default, 11 | delay 12 | } -------------------------------------------------------------------------------- /lcov.js: -------------------------------------------------------------------------------- 1 | import lcov2badge from 'lcov2badge'; 2 | import {writeFileSync} from 'fs'; 3 | 4 | lcov2badge.badge( 5 | './coverage/lcov.info', 6 | function(err, svgBadge){ 7 | if (err) throw err; 8 | writeFileSync('./coverage/lcov.svg', svgBadge); 9 | } 10 | ); -------------------------------------------------------------------------------- /licence: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Brandon Nozaki Miller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /local-node-ipc-certs/client.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIID+zCCAuOgAwIBAgIJAKUVVihb00q/MA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD 3 | VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNVGhvdXNhbmQg 4 | T2FrczEUMBIGA1UECgwLRGlnaU5vdyBpbmMxDDAKBgNVBAsMA1JuRDEQMA4GA1UE 5 | AwwHRGlnaU5vdzEhMB8GCSqGSIb3DQEJARYSYnJhbmRvbkBkaWdpbm93Lml0MB4X 6 | DTE2MDkxMDIxNTk0NloXDTE3MDkxMDIxNTk0NlowgZMxCzAJBgNVBAYTAlVTMRMw 7 | EQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1UaG91c2FuZCBPYWtzMRQwEgYD 8 | VQQKDAtEaWdpTm93IGluYzEMMAoGA1UECwwDUm5EMRAwDgYDVQQDDAdEaWdpTm93 9 | MSEwHwYJKoZIhvcNAQkBFhJicmFuZG9uQGRpZ2lub3cuaXQwggEiMA0GCSqGSIb3 10 | DQEBAQUAA4IBDwAwggEKAoIBAQCrNHWbbaMvlyK3ENevYeb+y5gWtOf5T8HS5k0E 11 | 7fub8jU4f4j7poxhvAYgaMeuUUigR3YZOSGc3N8yXFLFrrU8WQyK7KAwWcyUvqWK 12 | 7mvj6dQANtnGvnkt+q2pjMO1nxVPuXgov0GIaWHc7gL4rfuohBct6lbxOXaUxWHe 13 | FbQoWlqxs+lYaNMIMn7PgNwPDINoJeADKkVFXlNG9/YnT5j7TQegmzFxBBdko8EN 14 | W8Y91RG+/YHhtEPyKeQGrm3Ntl85JokT/GUsUUfUjXkuKrJsrLhwMVLPD23ucy7J 15 | zBcec0Vgpu99Bks51w/do6f80rIlAhI+iesZlPJjpDIYhmEXAgMBAAGjUDBOMB0G 16 | A1UdDgQWBBSOFk2HqjDTBqUuxOZvW0npEVRxCjAfBgNVHSMEGDAWgBSOFk2HqjDT 17 | BqUuxOZvW0npEVRxCjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAz 18 | FYxwSSbJ6wOX4yRNUU3XW0iGzoHwMtJhbYe3WRNLHRzHaRC+hg5VgBDEBcC9aYNB 19 | +dfNXfrQ+2uooe082twGqSyGVFYEytsTrhlzxvftunF0rMLXfI8wHkiqxWSupPYM 20 | nn2gFEVrJIpvyBnL6tAQpVRpn5aCBdQnmSApZVvDhogac0tQMH9GrjizrmDWtMoH 21 | V4zRA0UGzHfQoj+YKex7e9rPdDEx+mah0Ol1fzlmkZlOFInXJQ+t4F11bNNdHWje 22 | 7lyi0pFB9egtDUxwoHkzniMvef94cCIRsph+Vjisf7OQxnx65s+aPYcjrba+Kks3 23 | 58ANS3VkbXXzB3MeNGoB 24 | -----END CERTIFICATE----- 25 | -------------------------------------------------------------------------------- /local-node-ipc-certs/openssl.cnf: -------------------------------------------------------------------------------- 1 | # 2 | # OpenSSL example configuration file. 3 | # This is mostly being used for generation of certificate requests. 4 | # 5 | 6 | # This definition stops the following lines choking if HOME isn't 7 | # defined. 8 | HOME = . 9 | RANDFILE = $ENV::HOME/.rnd 10 | 11 | # Extra OBJECT IDENTIFIER info: 12 | #oid_file = $ENV::HOME/.oid 13 | oid_section = new_oids 14 | 15 | # To use this configuration file with the "-extfile" option of the 16 | # "openssl x509" utility, name here the section containing the 17 | # X.509v3 extensions to use: 18 | # extensions = 19 | # (Alternatively, use a configuration file that has only 20 | # X.509v3 extensions in its main [= default] section.) 21 | 22 | [ new_oids ] 23 | 24 | # We can add new OIDs in here for use by 'ca', 'req' and 'ts'. 25 | # Add a simple OID like this: 26 | # testoid1=1.2.3.4 27 | # Or use config file substitution like this: 28 | # testoid2=${testoid1}.5.6 29 | 30 | # Policies used by the TSA examples. 31 | tsa_policy1 = 1.2.3.4.1 32 | tsa_policy2 = 1.2.3.4.5.6 33 | tsa_policy3 = 1.2.3.4.5.7 34 | 35 | #################################################################### 36 | [ ca ] 37 | default_ca = CA_default # The default ca section 38 | 39 | #################################################################### 40 | [ CA_default ] 41 | 42 | dir = ./demoCA # Where everything is kept 43 | certs = $dir/certs # Where the issued certs are kept 44 | crl_dir = $dir/crl # Where the issued crl are kept 45 | database = $dir/index.txt # database index file. 46 | #unique_subject = no # Set to 'no' to allow creation of 47 | # several ctificates with same subject. 48 | new_certs_dir = $dir/newcerts # default place for new certs. 49 | 50 | certificate = $dir/cacert.pem # The CA certificate 51 | serial = $dir/serial # The current serial number 52 | crlnumber = $dir/crlnumber # the current crl number 53 | # must be commented out to leave a V1 CRL 54 | crl = $dir/crl.pem # The current CRL 55 | private_key = $dir/private/cakey.pem# The private key 56 | RANDFILE = $dir/private/.rand # private random number file 57 | 58 | x509_extensions = usr_cert # The extentions to add to the cert 59 | 60 | # Comment out the following two lines for the "traditional" 61 | # (and highly broken) format. 62 | name_opt = ca_default # Subject Name options 63 | cert_opt = ca_default # Certificate field options 64 | 65 | # Extension copying option: use with caution. 66 | # copy_extensions = copy 67 | 68 | # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs 69 | # so this is commented out by default to leave a V1 CRL. 70 | # crlnumber must also be commented out to leave a V1 CRL. 71 | # crl_extensions = crl_ext 72 | 73 | default_days = 365 # how long to certify for 74 | default_crl_days= 30 # how long before next CRL 75 | default_md = default # use public key default MD 76 | preserve = no # keep passed DN ordering 77 | 78 | # A few difference way of specifying how similar the request should look 79 | # For type CA, the listed attributes must be the same, and the optional 80 | # and supplied fields are just that :-) 81 | policy = policy_match 82 | 83 | # For the CA policy 84 | [ policy_match ] 85 | countryName = match 86 | stateOrProvinceName = match 87 | organizationName = match 88 | organizationalUnitName = optional 89 | commonName = supplied 90 | emailAddress = optional 91 | 92 | # For the 'anything' policy 93 | # At this point in time, you must list all acceptable 'object' 94 | # types. 95 | [ policy_anything ] 96 | countryName = optional 97 | stateOrProvinceName = optional 98 | localityName = optional 99 | organizationName = optional 100 | organizationalUnitName = optional 101 | commonName = supplied 102 | emailAddress = optional 103 | 104 | #################################################################### 105 | [ req ] 106 | default_bits = 2048 107 | default_keyfile = privkey.pem 108 | distinguished_name = req_distinguished_name 109 | attributes = req_attributes 110 | x509_extensions = v3_ca # The extentions to add to the self signed cert 111 | 112 | # Passwords for private keys if not present they will be prompted for 113 | # input_password = secret 114 | # output_password = secret 115 | 116 | # This sets a mask for permitted string types. There are several options. 117 | # default: PrintableString, T61String, BMPString. 118 | # pkix : PrintableString, BMPString (PKIX recommendation before 2004) 119 | # utf8only: only UTF8Strings (PKIX recommendation after 2004). 120 | # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). 121 | # MASK:XXXX a literal mask value. 122 | # WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. 123 | string_mask = utf8only 124 | 125 | req_extensions = v3_req # The extensions to add to a certificate request 126 | 127 | [ req_distinguished_name ] 128 | countryName = Country Name (2 letter code) 129 | countryName_default = AU 130 | countryName_min = 2 131 | countryName_max = 2 132 | 133 | stateOrProvinceName = State or Province Name (full name) 134 | stateOrProvinceName_default = Some-State 135 | 136 | localityName = Locality Name (eg, city) 137 | 138 | 0.organizationName = Organization Name (eg, company) 139 | 0.organizationName_default = Internet Widgits Pty Ltd 140 | 141 | # we can do this but it is not needed normally :-) 142 | #1.organizationName = Second Organization Name (eg, company) 143 | #1.organizationName_default = World Wide Web Pty Ltd 144 | 145 | organizationalUnitName = Organizational Unit Name (eg, section) 146 | #organizationalUnitName_default = 147 | 148 | commonName = Common Name (e.g. server FQDN or YOUR name) 149 | commonName_max = 64 150 | 151 | emailAddress = Email Address 152 | emailAddress_max = 64 153 | 154 | # SET-ex3 = SET extension number 3 155 | 156 | [ req_attributes ] 157 | challengePassword = A challenge password 158 | challengePassword_min = 4 159 | challengePassword_max = 20 160 | 161 | unstructuredName = An optional company name 162 | 163 | [ usr_cert ] 164 | 165 | # These extensions are added when 'ca' signs a request. 166 | 167 | # This goes against PKIX guidelines but some CAs do it and some software 168 | # requires this to avoid interpreting an end user certificate as a CA. 169 | 170 | basicConstraints=CA:FALSE 171 | 172 | # Here are some examples of the usage of nsCertType. If it is omitted 173 | # the certificate can be used for anything *except* object signing. 174 | 175 | # This is OK for an SSL server. 176 | # nsCertType = server 177 | 178 | # For an object signing certificate this would be used. 179 | # nsCertType = objsign 180 | 181 | # For normal client use this is typical 182 | # nsCertType = client, email 183 | 184 | # and for everything including object signing: 185 | # nsCertType = client, email, objsign 186 | 187 | # This is typical in keyUsage for a client certificate. 188 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment 189 | 190 | # This will be displayed in Netscape's comment listbox. 191 | nsComment = "OpenSSL Generated Certificate" 192 | 193 | # PKIX recommendations harmless if included in all certificates. 194 | subjectKeyIdentifier=hash 195 | authorityKeyIdentifier=keyid,issuer 196 | 197 | # This stuff is for subjectAltName and issuerAltname. 198 | # Import the email address. 199 | # subjectAltName=email:copy 200 | # An alternative to produce certificates that aren't 201 | # deprecated according to PKIX. 202 | # subjectAltName=email:move 203 | 204 | # Copy subject details 205 | # issuerAltName=issuer:copy 206 | 207 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem 208 | #nsBaseUrl 209 | #nsRevocationUrl 210 | #nsRenewalUrl 211 | #nsCaPolicyUrl 212 | #nsSslServerName 213 | 214 | # This is required for TSA certificates. 215 | # extendedKeyUsage = critical,timeStamping 216 | 217 | [ v3_req ] 218 | 219 | subjectAltName="DNS:localhost,IP:127.0.0.1" 220 | 221 | # Extensions to add to a certificate request 222 | 223 | basicConstraints = CA:FALSE 224 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 225 | 226 | [ v3_ca ] 227 | 228 | 229 | # Extensions for a typical CA 230 | 231 | 232 | # PKIX recommendation. 233 | 234 | subjectKeyIdentifier=hash 235 | 236 | authorityKeyIdentifier=keyid:always,issuer 237 | 238 | # This is what PKIX recommends but some broken software chokes on critical 239 | # extensions. 240 | #basicConstraints = critical,CA:true 241 | # So we do this instead. 242 | basicConstraints = CA:true 243 | 244 | # Key usage: this is typical for a CA certificate. However since it will 245 | # prevent it being used as an test self-signed certificate it is best 246 | # left out by default. 247 | # keyUsage = cRLSign, keyCertSign 248 | 249 | # Some might want this also 250 | # nsCertType = sslCA, emailCA 251 | 252 | # Include email address in subject alt name: another PKIX recommendation 253 | # subjectAltName=email:copy 254 | # Copy issuer details 255 | # issuerAltName=issuer:copy 256 | 257 | # DER hex encoding of an extension: beware experts only! 258 | # obj=DER:02:03 259 | # Where 'obj' is a standard or added object 260 | # You can even override a supported extension: 261 | # basicConstraints= critical, DER:30:03:01:01:FF 262 | 263 | [ crl_ext ] 264 | 265 | # CRL extensions. 266 | # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. 267 | 268 | # issuerAltName=issuer:copy 269 | authorityKeyIdentifier=keyid:always 270 | 271 | [ proxy_cert_ext ] 272 | # These extensions should be added when creating a proxy certificate 273 | 274 | # This goes against PKIX guidelines but some CAs do it and some software 275 | # requires this to avoid interpreting an end user certificate as a CA. 276 | 277 | basicConstraints=CA:FALSE 278 | 279 | # Here are some examples of the usage of nsCertType. If it is omitted 280 | # the certificate can be used for anything *except* object signing. 281 | 282 | # This is OK for an SSL server. 283 | # nsCertType = server 284 | 285 | # For an object signing certificate this would be used. 286 | # nsCertType = objsign 287 | 288 | # For normal client use this is typical 289 | # nsCertType = client, email 290 | 291 | # and for everything including object signing: 292 | # nsCertType = client, email, objsign 293 | 294 | # This is typical in keyUsage for a client certificate. 295 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment 296 | 297 | # This will be displayed in Netscape's comment listbox. 298 | nsComment = "OpenSSL Generated Certificate" 299 | 300 | # PKIX recommendations harmless if included in all certificates. 301 | subjectKeyIdentifier=hash 302 | authorityKeyIdentifier=keyid,issuer 303 | 304 | # This stuff is for subjectAltName and issuerAltname. 305 | # Import the email address. 306 | # subjectAltName=email:copy 307 | # An alternative to produce certificates that aren't 308 | # deprecated according to PKIX. 309 | # subjectAltName=email:move 310 | 311 | # Copy subject details 312 | # issuerAltName=issuer:copy 313 | 314 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem 315 | #nsBaseUrl 316 | #nsRevocationUrl 317 | #nsRenewalUrl 318 | #nsCaPolicyUrl 319 | #nsSslServerName 320 | 321 | # This really needs to be in place for it to be a proxy certificate. 322 | proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo 323 | 324 | #################################################################### 325 | [ tsa ] 326 | 327 | default_tsa = tsa_config1 # the default TSA section 328 | 329 | [ tsa_config1 ] 330 | 331 | # These are used by the TSA reply generation only. 332 | dir = ./demoCA # TSA root directory 333 | serial = $dir/tsaserial # The current serial number (mandatory) 334 | crypto_device = builtin # OpenSSL engine to use for signing 335 | signer_cert = $dir/tsacert.pem # The TSA signing certificate 336 | # (optional) 337 | certs = $dir/cacert.pem # Certificate chain to include in reply 338 | # (optional) 339 | signer_key = $dir/private/tsakey.pem # The TSA private key (optional) 340 | 341 | default_policy = tsa_policy1 # Policy if request did not specify it 342 | # (optional) 343 | other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) 344 | digests = md5, sha1 # Acceptable message digests (mandatory) 345 | accuracy = secs:1, millisecs:500, microsecs:100 # (optional) 346 | clock_precision_digits = 0 # number of digits after dot. (optional) 347 | ordering = yes # Is ordering defined for timestamps? 348 | # (optional, default: no) 349 | tsa_name = yes # Must the TSA name be included in the reply? 350 | # (optional, default: no) 351 | ess_cert_id_chain = no # Must the ESS cert id chain be included? 352 | # (optional, default: no) 353 | -------------------------------------------------------------------------------- /local-node-ipc-certs/private/client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAqzR1m22jL5citxDXr2Hm/suYFrTn+U/B0uZNBO37m/I1OH+I 3 | +6aMYbwGIGjHrlFIoEd2GTkhnNzfMlxSxa61PFkMiuygMFnMlL6liu5r4+nUADbZ 4 | xr55LfqtqYzDtZ8VT7l4KL9BiGlh3O4C+K37qIQXLepW8Tl2lMVh3hW0KFpasbPp 5 | WGjTCDJ+z4DcDwyDaCXgAypFRV5TRvf2J0+Y+00HoJsxcQQXZKPBDVvGPdURvv2B 6 | 4bRD8inkBq5tzbZfOSaJE/xlLFFH1I15LiqybKy4cDFSzw9t7nMuycwXHnNFYKbv 7 | fQZLOdcP3aOn/NKyJQISPonrGZTyY6QyGIZhFwIDAQABAoIBAHpxZ1dE/zuvFLXm 8 | xsr48vLxexFqSqnEv/NsoFLRPWzXufZxR+/qumW/yoXtSjpCifWPhkgd0wtT8BEd 9 | dFlLTPUfHthQyXQrFSSggNavE9yJxARvNits2E/pA8DKGsJPRzeghu5lcqHz9HjE 10 | hL2D+QMZjVZaTdnx5fwaepcR4KomYTUupci0HoMWyoKPhIfItVueiHVo4d60dIRz 11 | OpkSGCAZ/Czv5CJrmK/5e+roKti4ChF/n28hUu7OGzvkG+qYep08tf48MyZCPHgO 12 | Vj+kuxMRkjIP0iXLmiF32lZXzpOFvjtXovI46dYiINCE9tNyKqDWYUJf9qNqwAsm 13 | OuOfXtkCgYEA18Ywabu/Z4vYUhWtTFrP6iSLVcXd0rZuWud7kwv/G4DMrNh7oi1s 14 | 0AVvphaEqEn8OsgcuyIlyjtJl60aQzvYwdu2KEcTjcqvUX7p/41t5O/LzaYwZ3hh 15 | 9oFIWXXFpskg7Kh0EGCGG/yvAdTai5M0lO9XQ1DUK0MWc1KQ5yKd0mUCgYEAyx80 16 | dgIZTyHl0ZgF712mRda5KfQlmgWoo0zu/IFSFuINEMC/3laYEJCowOnUb8VZ8mbJ 17 | Wd/FhOTadv7joY0eAhfSNAItaubuZWo91bbD2vwpi/U2OEfy0LzF7BNXHCpH69wk 18 | vujKBxmRTGvBLbabcWA97UPFM2K33rsM72DAL8sCgYB03SOFcKk3BLfRpWnpy9mF 19 | /+rzNqpwoFveojb8qmet1rGD/+/eI2omtHsG4nVQzFlu4Mkm1VTQVhICsz9hIL3C 20 | KSRcZjqB9j/EDM/hmBDoCLRCGntm3v13zAeKZE37ij1pz8akxBJ+f/mtLUJ8i+rT 21 | q1mA3Ps8vyYeqZ5PgSEnPQKBgD6szEU1dJXEQeOgYwRvAyU9kjjtysRxxo1M6dkk 22 | Fi5VZe6rawix84349PlBrXknjg+Lw8llkM7mxro9AAQTRRUkQIonudfoldrZI2dU 23 | U664bCFxcl9/Y98gwHmNpi1cpoCSlwwJTH1QWFMaVKtEU0ZyiekyJiEq7s1dLiqW 24 | 0fZtAoGABvAOikMmOn6ewt+NyYd6HkwgcvI0R0aHxOQz8aldW4gwrkuvuOOHdfah 25 | RAcc8LiZFqhNFN7DMkRt1crtP5v3vh2Nbyf9Zg2ZizsIupsNlvSlh/aTueVozVuM 26 | hc/wEVlrqeJInf4jkxYna6G6CoTfPVyQCjNcvlI3kMfIoyXS+vc= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /local-node-ipc-certs/private/dhparam.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN DH PARAMETERS----- 2 | MIIBCAKCAQEAhDA93df5Qa7pMWiqJ8IeCDw4fCIJCNbzRklS2saOeQRkUY/kPy07 3 | EByFWUDNtgtWRx7YndJKwyFepHXxI3P0DDuSPYKq/bfiWDr/cUmTBJcpPmg6w/SU 4 | ReOB6vORXyF9iytyLCKk1Pyo2nXOdpADcTflhi+zxTSpGLtPAU2XIYENtmC4HKJm 5 | y6nbSIbe4BA74bxyqzp6RVuMvyHAgCjPDwvHlp5UV1Mjtr1aNqgzpLQSjK4VwiJ+ 6 | DZ48/1D9IYksDl8NWJopFpudyPD1WFou/CZ6PYsjprFrTKVPqoFD5Zj6zPey9C70 7 | Go0uHRNPr9UrhwCqDEKNszulME8heSVSQwIBAg== 8 | -----END DH PARAMETERS----- 9 | -------------------------------------------------------------------------------- /local-node-ipc-certs/private/oldclient.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAvmw4yTAd5EdNxksnKEx+ky8XgEqTJVAvcrgF1jaPrC0QNr94 3 | EfEHouiEyqWlf4kDzksIA9HcuGhVPZ9gsjjgLvi1pwT+e2vfyOHOWOf96NDlfW02 4 | Fx6d92k1zEfhfVmTJU0j6ANG2eNMfF5rhK+xKzH3FC0Vm5e7np9wVuRD4CjggJJL 5 | fBm6xJPSBWeY1gum3m5sH4Ec3X0zacZXeBOdjMx1a5I2gfTHJe5fizDfw1vgsYhh 6 | I3z6OEXEg5kFtOiz34y4SVCDRZGDVXiAdx8uVXXPdryFybjiZGWGEeTFDZfCAuZp 7 | h0I04cqfniD5FbSPIdVVAImH9Nm1sbpLafyuXwIDAQABAoIBADTd8OoSXMoq7bHW 8 | 3Zk3m5Cba2fnzHB4kaPE6YHuhfbkT/MTN2+rvlYBPhTQ5mDBFnhopmIBGslr1faU 9 | 0BDK75q63BvxrAFyEqA/6L0QM5M2o/AtqO3ER1EQOapsbnMRsmORxh09A6esjmid 10 | AjbFXGfEqHdGiRA4kRNZ6qOFHj8WP4FZ3/elIerl4W86FtMeuza6PUMYm1ePFG/h 11 | vTGROXibW2/qrfzgsocKgdjc06Szi95hjloHlpPo3OVLywSNYuJ6dxOj11tKBIjr 12 | U126cdza/2OeyWasY4tl4WVeG1Mojtya2ObvMNMOyESPzKaVzb2LIN6feH7toxdK 13 | 5CEbzfkCgYEA5kZzFWLvUAkK/Oi0bK9b1WhmNUOcfZmPOBJenurfKSQo2R4ugvAM 14 | zMupVs/Mum0Hl1+cvTPZDAwHx0qM3E8+Ute7SqLOMxlx7b1XCFB03RN1UN4BCSy4 15 | hCQPi+f3YjAF/Zpduquq9qS4gcIwhlo3FHGWWFFIGDesWfJrsTsssNUCgYEA07IM 16 | K5+AsvdrHMShMMbys4rOitY9JKUMKV1BdsyRw9z/rsWoDcqupuFTPwWrlc3D3a/i 17 | /b/cM3Wm8907fPPrauU3LF11tOkIhsP8/xRkK9BZGkjJCSLO5UvWxmlcZreGvHh+ 18 | QAwPWKh8MsatyFBFmn7SGFXSu88LQL+TGilpHGMCgYAOwBiDGDFIKSwhAy77f0gc 19 | pXFWnBwcF4gLCXIyL81Xr09GiR5lmMbZH3qbavgsQOupkKBTpkyS7vpYk7fuLM1L 20 | NTJ0F3Wp5Eld9zDqAW1a8/Ih2farBchT/pNYXOWFzpmzov26BWEQJ4ECHtRI5uJ8 21 | VsJQqfQ6SOarZFHtqmK0eQKBgQCPwWCyXuYuogWCy6QKU4+MjL4lWca7k7jmfgVu 22 | fwydTP3z2RV+CB0CBhFZwqf6Wnifmkkyt475AvQUti8ncxxywqTs46qC55x6p6yu 23 | K1K6zgkz6Clcot6Mpyt6ISI2PnqokcpqA8aIFiIA+RoZ5Sje+TAChoVMNBUYKv/h 24 | zC0ssQKBgEXyFNRGHul7ku8Ss6ZZBZjQEOFdpu7npbZWcqy273tKOdV6uOG93rQX 25 | 6Ez6yxuBepSdwP716CT7o8EaSPBy+QjDH/e2qI3rIUHzfPwAwf4kGbNa6relTCVR 26 | fLrzEICSbFZKST/zeKvrY0ACOCIn8b6LiiP7GJfnV8bvvpTWXyil 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /local-node-ipc-certs/private/oldserver.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAyHKCBWzkf58gKkqRIBjJR8cSXlsiuOuirlbBQ1K+recVbh2b 3 | MdDoqBCk3ibeGw4p/smOxJiH/9rxpcCQ0XrSeNGasLxGB8RcNgenRFonyBPmTAjS 4 | O85Aa74g8CUBXaYSgk0hMWQNxkkHecGuu9F6LtN5TM7XG6Td7OTRB+bDEGdwfny4 5 | bqc2ELUsj99CVNxSNc5h0dJE9M6ejvIjdRQFFtfNKGgT3O7inEdDSpPZfeM+JmTB 6 | r/vz2jnHaSsD7d9hWKYo7Kp74rL0QJSH97ugb+g8kDAkqV1bQaVdzp+nC74/GbVL 7 | B9E+YH+zzvs2x9nLYPJHknia5KRfOmRjPnCdVwIDAQABAoIBACdNXHUX3s2vM61X 8 | JZF3iq/KNq3NjMdZXHJ2jDpZFQ4gCzGmGHHyFkwtx0XPtSj05AMTHi0qAzCFi3AG 9 | i96nCHGsF3qjz89iDvqBEajzTG2MiVFLQX18eWEmzGqJtvTXxTVLTkDS72h7lT2o 10 | XkxxTFW2HUiUHdVLxD/Ytauo8YJbjGJM5pdCxEp+uJbYWYwsvvfE4IHb8LJmqtOP 11 | fUG/wR3mjmHYYcYXKEqiDkSnxJL9vWb2lYKht1NFUyeVkv6q5dkr0JeSD6jw84by 12 | MiHoXsxjXmjn3JPtNfid92kIsMjsZ54oZ5ep2iUW7WpTZJnideyZCa4mIRn3BZZ6 13 | TPpIKVECgYEA/m7kwNG+WamLLGmgUkq9xWngHvkKaHsjnGuDGi8bYObtzAiOzoPi 14 | Bav0V/cJeTjZJJ3uW4HGhzmkJCDq+R3kJ9lEBYy9N0cq0tQf/IRorri7SbHm+eP3 15 | +B26z91Vkn0sqV3Htg+78jnjLYV6Nfy4pBvs3u7O91EM7kj3Q8A/xOUCgYEAya6B 16 | 1fsngVVfkdQ6OmsibpWWCksBbN1Ko+bnY8ZoyTWeS2LkPFVn5lihJ9XzTTV+b/s2 17 | 6urtTpCiQo/WAT62ATI2J5xHLBVS46CJj6HP9jPsyIxSEAor7wmKXqCaQDG1J7Zt 18 | 2IszGtg3WYRWgrNSPtYdeB14fGhbpMphigZvkYsCgYAZUvpLwtSaYgirK/w8FJpc 19 | 2tPm4UzK52688+qBoays8W87vqJQJcpKXDoew0TbHvBl954w13LmJLOUsP4SO4po 20 | +PQPRVnT9a5qe5iPbrJoqZRimmVt++XDeVoNtG7+/JyEYwQst9YyHtbgwgdO9k9+ 21 | bhUef1B0R0ntMbACu1DdjQKBgGEzq/vXmkipPvBn2tCBBg1KJxA66irv1KN+DBN4 22 | ctRW9T3cIag6eWL5YGJ0qViS6adK6kL6ivkMmEeAT2I2OT4GVzdsCJlkhZiTrPj+ 23 | wd4lVH+rsXltjZMdhATrXqyFyIulTvfIzw6nGrYYJCHGD2OdioJzobhEC7c2myAM 24 | zgTVAoGADfGqbgq8wSv+nLtOnY+s5ajwMVAyld/JqDXm5829CTI/Kd1ch6BxWYZr 25 | V06PY9mJ8k39GAOab7YWcKX90E85cN7YMSjsQhdMgVAsBCv25eot4BWc8EO8WeCJ 26 | 76aC7LlmX9WlHqaZV/GNcj3PhKao5mIk77BKySxINRaflRiCWjI= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /local-node-ipc-certs/private/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAw+YwIWPQAh8WlhPAaasfUyb13Fcg0P0y+UmtAHpAxnUKAxc1 3 | /bkl4FNjbS+kkTGkIvRE4NHJh4DMqEDBsf7mwhfaOl8bTCoustyh14bzxJKdM1Cx 4 | Q/L2GsTIwF1vZCvqOvrV1glLruRrw8PvSFaWt1JAZ8CUhtyddR3itkSF+suTORxh 5 | +aUjUreyfuaWx0dfIQLYOxMeTa/g94Ar9Q7KPCXgxmDqu8DVCmurDH2jz6iFktbp 6 | +iNvrUfs88Y3I0E8/QRBAK37j7fEp296QcYIDJKkS2z2lenJykAdaqF9qLhb3zrM 7 | UpGt5VUUSNdHeXzCQr7J9wA7TWjCXnQh3d/xlwIDAQABAoIBACUSQHVxIAHmxC1u 8 | W3Ejsu/XZZtm2Yzy/VxzdsuqVuu3ZkejctIq4WIMJbqZ03iufjMnKomo6Yw88X29 9 | k2oNpLmCLgfxy4akTOYIHpBct3CxlhIJ6SHErpHuP1c310aLkO3MXf79D1dvXn1T 10 | bMqxqB/U7t8zcGf9A8cP+sEnQnttCdj2ayUlDqfPV06sDRPndIS2LFkzIswwHED8 11 | Z9jRk6tWg+APsEgFAo58lIEYM2iR04c2ffWBvffIEWotYM4YH1pdgvVtILLzky8C 12 | IogcF/LWe4mFKgBi8O3cS03YowoPgkPBh/4lXBiCXio5rkKJaMJrJMNDmoQTSzqU 13 | 80r8zuECgYEA8PqoY3p6lpUIxR1i4jrDzcmnFJ8vNoehr4SySR8G5EkPloltT0OK 14 | o1d7g/b19RbulR7XnMq/H4Ic5GDiP2EEI5zM093JbV5luQZHwKrqTykXVdlgiDan 15 | GAxsJ9Q31ASAixCA92una1+08Xe8N7aNBuJNPuvaPB2603dO30hIlQkCgYEA0Bwu 16 | oqZMh8Td4pB3nUQM08NiLrYy1vwzbAHhOx3VxRGiF7x8X32NSnAzQmusqYuT6j02 17 | o4Jg0Jyn+XV67AD4f0D8+4urQEnrfnf32GxSvefucFbekypGLR8w3WR18mkBhVst 18 | WTkKqZwoJtmyJlbSRRpDZ6ewQqZ/a79NmMkxmZ8CgYEAwQQ0jgGTYTucW64u/v+M 19 | yC8l2dmrCmVW92w1FWZ5sa5ngu8uk9eIm06+CzRrS1WD4gNjNh4bOdSQ6chET/mY 20 | RCIa2fSCm0yJ88p4/HSp2qASJdxIerIz4opIsxpDYVn9z+V3NzaOUe3F08dRBdr9 21 | WK84qhZlpdM2Spz8mtGd+WkCgYBCV3mWaCUlcuC5BQzcmYDtUO/PrE1ws11BJShD 22 | zDMFa6Wco32Sg1ezTylIF0MnmVNB7NmqLjnmxsnVgFn7OiP9jR4YomGpUOc9ncjo 23 | uT93QqSEM20oxOUyJStSqF/hMxBFDtfaBZEcmKdEG0nrZuoJFWI/fPl3hdRA6O83 24 | sYuaSQKBgQCGTN1vEshVEu2Sbdpw+9p/JpHOWT4HuTU78EGfjd4wDtWgme3WgbB4 25 | geixhSTsoGdb95Da5Wp81nEUN7P/VE9VTX74qcXD3AseCYmhmbFaZTOi0kjYEbAQ 26 | wGuBa8CDIzttKhBsBQWZpG7YQq3pOqKLgKOuwwf6kJk1eh+HMS7ktQ== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /local-node-ipc-certs/server.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIID+zCCAuOgAwIBAgIJANhisawO7GXuMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD 3 | VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNVGhvdXNhbmQg 4 | T2FrczEUMBIGA1UECgwLRGlnaU5vdyBJbmMxDDAKBgNVBAsMA1JuRDEQMA4GA1UE 5 | AwwHRGlnaU5vdzEhMB8GCSqGSIb3DQEJARYSYnJhbmRvbkBkaWdpbm93Lml0MB4X 6 | DTE2MDkxMDIxMDIwNFoXDTE3MDkxMDIxMDIwNFowgZMxCzAJBgNVBAYTAlVTMRMw 7 | EQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1UaG91c2FuZCBPYWtzMRQwEgYD 8 | VQQKDAtEaWdpTm93IEluYzEMMAoGA1UECwwDUm5EMRAwDgYDVQQDDAdEaWdpTm93 9 | MSEwHwYJKoZIhvcNAQkBFhJicmFuZG9uQGRpZ2lub3cuaXQwggEiMA0GCSqGSIb3 10 | DQEBAQUAA4IBDwAwggEKAoIBAQDD5jAhY9ACHxaWE8Bpqx9TJvXcVyDQ/TL5Sa0A 11 | ekDGdQoDFzX9uSXgU2NtL6SRMaQi9ETg0cmHgMyoQMGx/ubCF9o6XxtMKi6y3KHX 12 | hvPEkp0zULFD8vYaxMjAXW9kK+o6+tXWCUuu5GvDw+9IVpa3UkBnwJSG3J11HeK2 13 | RIX6y5M5HGH5pSNSt7J+5pbHR18hAtg7Ex5Nr+D3gCv1Dso8JeDGYOq7wNUKa6sM 14 | faPPqIWS1un6I2+tR+zzxjcjQTz9BEEArfuPt8Snb3pBxggMkqRLbPaV6cnKQB1q 15 | oX2ouFvfOsxSka3lVRRI10d5fMJCvsn3ADtNaMJedCHd3/GXAgMBAAGjUDBOMB0G 16 | A1UdDgQWBBSWtsrqQGryJVSJER5int40YIpuxjAfBgNVHSMEGDAWgBSWtsrqQGry 17 | JVSJER5int40YIpuxjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQDA 18 | NySrqGBF+h/UCph/YEXTTea8MQIvihLecZ0VpZ/0VDZfwxzZns5oV0znoZEQcyYZ 19 | olTr40jyCt0Ex59VRWRUUfdR1JgZtaMd29iYxUvGy+tK5pw75mIl3upc8hEe2uzN 20 | c8hynlLSh9y75GM3RUkUlkSIrIRQIvOTW1+lhqBzhesvYjScCbH8MXL5e6qCkbhZ 21 | tP5xuTjQlY38oJxDmMHmIxholxCxQtnEVTpKn0lp2diPMXU9qbsTuZ9eYTwZabSk 22 | +CXrtjYtaZPkHGDSldWdMdbHw/+81ViMA3CA2f61aqTcIYyAZz8o9b+4IghLLicZ 23 | C84hYbMbCAz0rp6bt+PJ 24 | -----END CERTIFICATE----- 25 | -------------------------------------------------------------------------------- /node-ipc.js: -------------------------------------------------------------------------------- 1 | import IPC from './services/IPC.js'; 2 | 3 | class IPCModule extends IPC{ 4 | constructor(){ 5 | super(); 6 | 7 | } 8 | 9 | IPC=IPC; 10 | } 11 | 12 | const singleton=new IPCModule; 13 | 14 | export { 15 | singleton as default, 16 | IPCModule 17 | } 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@achrinza/node-ipc", 3 | "version": "10.1.11", 4 | "description": "A nodejs module for local and remote Inter Process Communication (IPC), Neural Networking, and able to facilitate machine learning.", 5 | "type": "module", 6 | "main": "node-ipc.cjs", 7 | "module": "node-ipc.js", 8 | "exports": { 9 | "import": "./node-ipc.js", 10 | "require": "./node-ipc.cjs" 11 | }, 12 | "directories": { 13 | "example": "example" 14 | }, 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "engines": { 19 | "node": "14 || 16 || 17 || 18 || 19 || 20 || 22" 20 | }, 21 | "dependencies": { 22 | "@achrinza/event-pubsub": "5.0.11", 23 | "@achrinza/strong-type": "1.1.20", 24 | "@node-ipc/js-queue": "2.0.3", 25 | "js-message": "1.0.7" 26 | }, 27 | "devDependencies": { 28 | "@node-ipc/vanilla-test": "1.4.15", 29 | "c8": "^7.7.3", 30 | "esbuild": "^0.12.28", 31 | "lcov2badge": "^0.1.2", 32 | "lockfile-lint": "^4.7.4", 33 | "node-cmd": "4.0.0", 34 | "node-http-server": "^8.1.4" 35 | }, 36 | "scripts": { 37 | "prepare": "esbuild node-ipc.js --bundle --format=cjs --target=es2018 --platform=node --outfile=node-ipc.cjs", 38 | "test": "c8 -r lcov -r html node test/CI.js && c8 report && node ./lcov.js", 39 | "coverage": "echo 'See your coverage report at http://localhost:8080' && node-http-server port=8080 root=./coverage/" 40 | }, 41 | "keywords": [ 42 | "IPC", 43 | "Neural Networking", 44 | "Machine Learning", 45 | "inter", 46 | "process", 47 | "communication", 48 | "unix", 49 | "windows", 50 | "win", 51 | "socket", 52 | "TCP", 53 | "UDP", 54 | "domain", 55 | "sockets", 56 | "threaded", 57 | "communication", 58 | "multi", 59 | "process", 60 | "shared", 61 | "memory" 62 | ], 63 | "author": "Brandon Nozaki Miller", 64 | "license": "MIT", 65 | "repository": { 66 | "type": "git", 67 | "url": "https://github.com/achrinza/node-ipc.git" 68 | }, 69 | "bugs": { 70 | "url": "https://github.com/achrinza/node-ipc/issues" 71 | }, 72 | "homepage": "https://github.com/achrinza/node-ipc" 73 | } 74 | -------------------------------------------------------------------------------- /services/IPC.js: -------------------------------------------------------------------------------- 1 | 2 | import Defaults from '../entities/Defaults.js'; 3 | import Client from '../dao/client.js'; 4 | import Server from '../dao/socketServer.js'; 5 | import util from 'util'; 6 | 7 | class IPC{ 8 | constructor(){ 9 | 10 | } 11 | 12 | //public members 13 | config=new Defaults; 14 | of={}; 15 | server=false; 16 | 17 | //protected methods 18 | get connectTo(){ 19 | return connect; 20 | } 21 | get connectToNet(){ 22 | return connectNet; 23 | } 24 | get disconnect(){ 25 | return disconnect 26 | } 27 | get serve(){ 28 | return serve; 29 | } 30 | get serveNet(){ 31 | return serveNet; 32 | } 33 | get log(){ 34 | return log; 35 | } 36 | 37 | set connectTo(value){ 38 | return connect; 39 | } 40 | set connectToNet(value){ 41 | return connectNet; 42 | } 43 | set disconnect(value){ 44 | return disconnect 45 | } 46 | set serve(value){ 47 | return serve; 48 | } 49 | set serveNet(value){ 50 | return serveNet; 51 | } 52 | set log(value){ 53 | return log; 54 | } 55 | } 56 | 57 | 58 | 59 | function log(...args){ 60 | if(this.config.silent){ 61 | return; 62 | } 63 | 64 | for(let i=0, count=args.length; i