From 7d6705e5a0d7fbce5907589d3ee909bde51a3810 Mon Sep 17 00:00:00 2001 From: Brandon Nozaki Miller Date: Thu, 27 Feb 2014 16:04:14 -0800 Subject: [PATCH] Create gh-pages branch via GitHub --- index.html | 599 ++++++++++++++++++++++++++++++++++------------------ params.json | 2 +- 2 files changed, 393 insertions(+), 208 deletions(-) diff --git a/index.html b/index.html index 5266d8f..d35e7bc 100644 --- a/index.html +++ b/index.html @@ -34,45 +34,416 @@

node-ipc

-

a nodejs module for local and remote Inter Process Communication

+

a nodejs module for local and remote Inter Process Communication for Linux, Mac and Windows.

-

npm install node-ipc

+

npm install node-ipc
alt node-ipc npm details

-

this is a new project so more documentation will come

+

Package details websites :

-

+

Types of IPC Sockets

+ - + + + + -
TypeStability Definition
Unix SocketGives lightning fast communication and avoids the network card to reduce overhead and latency. Local Unix Socket examples +StableGives Linux and Mac lightning fast communication and avoids the network card to reduce overhead and latency. Local Unix Socket examples
TCP SocketStable Gives the most reliable communication across the network. Can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because TCP sockets go through the network card while Unix Sockets do not. Local or remote network TCP Socket examples
TLS SocketAlpha coming soon...
UDP SocketsStable Gives the fastest network communication. UDP is less reliable but much faster than TCP. It is best used for streaming non critical data like sound, video, or multiplayer game data as it can drop packets depending on network connectivity and other factors. UDP can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because UDP sockets go through the network card while Unix Sockets do not. Local or remote network UDP Socket examples

-IPC Default Variables

+ + + + + + + + + + + + + + + + + + + +
OSSupported Sockets
LinuxUnix, TCP, TLS, UDP
MacUnix, TCP, TLS, UDP
WinTCP, TLS, UDP

Windows users may want to use UDP servers for the fastest local IPC. Unix Servers are the fastest oprion on Linux and Mac, but not available for windows.

-

ipc.config

+

+IPC Methods

+ +

These methods are available in the IPC Scope.

+ +
+log
+ +

ipc.log(a,b,c,d,e...);

+ +

ipc.log will accept any number of arguments and if ipc.config.silent is not set, it will concat them all with a sincle space ' ' between them and then log them to the console. This is fast because it prevents any concation from happening if the ipc is set to silent. That way if you leave your logging in place it should not effect performance.

+ +

the log also supports colors implementation. All of the available styles are supported and the theme styles are as follows :

+ +
{
+    good    : 'green',
+    notice  : 'yellow',
+    warn    : 'red',
+    error   : 'redBG',
+    debug   : 'magenta',
+    variable: 'cyan',
+    data    : 'blue'
+}    
+
+ +

You can override any of these settings by requireing colors and setting the theme as follows :

+ +
var colors=require('colors');
+
+colors.setTheme(
+    {
+        good    : 'zebra',
+        notice  : 'redBG',
+        ...
+    }    
+);
+
+ +
+connectTo
+ +

ipc.connectTo(id,path,callback);

+ +

Used for connecting as a client to local Unix Sockets. This is the fastst way for processes on the same machine to communicate because it bypasses the network card which TCP and UDP must both use.

+ + + + + + + + + + + + + + + + + + + + + + + + +
variablerequireddefinition
idrequiredis the string id of the socket being connected to. The socket with this id is added to the ipc.of object when created.
pathoptionalis the path of the Unix Domain Socket File, if not set this will be defaylted to ipc.config.socketRoot+ipc.config.appspace+id +
callbackoptionalthis is the function to execute when the socket has been created.

examples arguments can be ommitted solong as they are still in order.

+ +
ipc.connectTo('world');
+
+ +

or using just an id and a callback

+ +
ipc.connectTo(
+    'world',
+    function(){
+        ipc.of.world.on(
+            'hello',
+            function(data){
+                ipc.log(data.debug); 
+                //if data was a string, it would have the color set to the debug style applied to it
+            }
+        )
+    }
+);
+
+ +

or explicitly setting the path

+ +
ipc.connectTo(
+    'world',
+    'myapp.world'
+);
+
+ +

or explicitly setting the path with callback

+ +
ipc.connectTo(
+    'world',
+    'myapp.world',
+    function(){
+        ...
+    }
+);
+
+ +
+connectToNet
+ +

ipc.connectToNet(id,host,port,callback)

+ +

Used to connect as a client to a TCP or TLS socket via the network card. This can be local or remote, if local, it is recommended that you use the Unix Socket Implementaion of connectTo instead as it is much faster since it avoids the network card alltogether.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
variablerequireddefinition
idrequiredis the string id of the socket being connected to. For TCP & TLS sockets, this id is added to the ipc.of object when the socket is created with a refrence to the socket.
hostoptionalis the host on which the TCP or TLS socket resides. This will default to ipc.config.networkHost if not specified.
portoptionalthe port on which the TCP or TLS socket resides.
callbackoptionalthis is the function to execute when the socket has been created.

examples arguments can be ommitted solong as they are still in order.
+So while the default is : (id,host,port,callback), the following examples will still work because they are still in order (id,port,callback) or (id,host,callback) or (id,port) etc.

+ +
ipc.connectToNet('world');
+
+ +

or using just an id and a callback

+ +
ipc.connectToNet(
+    'world',
+    function(){
+        ...
+    }
+);
+
+ +

or explicitly setting the host and path

+ +
ipc.connectToNet(
+    'world',
+    'myapp.com',serve(path,callback)
+    3435
+);
+
+ +

or only explicitly setting port and callback

+ +
ipc.connectToNet(
+    'world',
+    3435,
+    function(){
+        ...
+    }
+);
+
+ +
+serve
+ +

ipc.serve(path,callback);

+ +

Used to create local Unix Socket Server to which Clients can bind. The server can emit events to specific Client Sockets, or broadcast events to all known Client Sockets.

+ + + + + + + + + + + + + + + + + + + +
variablerequireddefinition
pathoptionalThis is the Unix Domain Socket path to bind to. If not supplied, it will default to : ipc.config.socketRoot + ipc.config.appspace + ipc.config.id;
callbackoptionalThis is a function to be called after the Server has started. This can also be done by binding an event to the start event like ipc.server.on('start',function(){}); +

examples arguments can be ommitted solong as they are still in order.

+ +
ipc.serve();
+
+ +

or specifying callback

+ +
ipc.serve(
+    function(){...}
+);
+
+ +

or specify path

+ +
ipc.serve(
+    '/tmp/myapp.myservice'
+);
+
+ +

or specifying everything

+ +
ipc.serve(
+    '/tmp/myapp.myservice',
+    function(){...}
+);
+
+ +
+serveNet
+ +

serveNet(host,port,UDPType,callback)

+ +

Used to create TCP, TLS or UDP Socket Server to which Clients can bind or other servers can send data to. The server can emit events to specific Client Sockets, or broadcast events to all known Client Sockets.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
variablerequireddefinition
hostoptionalIf not specified this defaults to localhost. For TCP, TLS & UDP servers this is most likely going to be localhost or 0.0.0.0 unless you have something like node-http-server installed to run subdomains for you.
portoptionalThe port on which the TCP, UDP, or TLS Socket server will be bound, this defaults to 8000 if not specified
UDPTypeoptionalIf set this will create the server as a UDP socket. 'udp4' or 'udp6' are valid values. This defaults to not being set.
callbackoptionalFunction to be called when the server is created

examples arguments can be ommitted solong as they are still in order.

+ +

default tcp server

+ +
ipc.serveNet();
+
+ +

default udp server

+ +
ipc.serveNet('udp4');
+
+ +

or specifying TCP server with callback

+ +
ipc.serveNet(
+    function(){...}
+);
+
+ +

or specifying UDP server with callback

+ +
ipc.serveNet(
+    'udp4',
+    function(){...}
+);
+
+ +

or specify port

+ +
ipc.serveNet(
+    3435
+);
+
+ +

or specifying everything TCP

+ +
ipc.serveNet(
+    'MyMostAwesomeApp.com',
+    3435,
+    function(){...}
+);
+
+ +

or specifying everything UDP

+ +
ipc.serveNet(
+    'MyMostAwesomeApp.com',
+    3435,
+    'udp4',
+    function(){...}
+);
+
+ +

+IPC Stores and Default Variables

+ +

ipc.of

+ +

This is where socket connection refrences will be stored when connecting to them as a client via the ipc.connectTo or iupc.connectToNet.

+ +

example

+ +
ipc.connectTo(
+    'world',
+    function(){
+
+        ipc.of.world.on(
+            'message',
+            function(data){...}
+        );
+
+    }
+);
+
+ +

ipc.config

Set these variables in the ipc.config scope to overwrite or set default values.

@@ -132,203 +503,7 @@ this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. -

-IPC Methods

- -

These methods are available in the IPC Scope.

- -
-log
- -

ipc.log(a,b,c,d,e...);

- -

ipc.log will accept any number of arguments and if ipc.config.silent is not set, it will concat them all with a sincle space ' ' between them and then log them to the console. This is fast because it prevents any concation from happening if the ipc is set to silent. That way if you leave your logging in place it should not effect performance.

- -

the log also supports colors implementation. All of the available styles are supported and the theme styles are as follows :

- -
{
-    good    : 'green',
-    notice  : 'yellow',
-    warn    : 'red',
-    error   : 'redBG',
-    debug   : 'magenta',
-    variable: 'cyan',
-    data    : 'blue'
-}    
-
- -

You can override any of these settings by requireing colors and setting the theme as follows :

- -
var colors=require('colors');
-
-colors.setTheme(
-    {
-        good    : 'zebra',
-        notice  : 'redBG',
-        ...
-    }    
-);
-
- -
-connectTo
- -

ipc.connectTo(id,path,callback);

- -

Used for connecting as a client to local Unix Sockets. This is the fastst way for processes on the same machine to communicate because it bypasses the network card which TCP and UDP must both use.

- -
    -
  1. -id required is the string id of the socket being connected to. The socket with this id is added to the ipc.of object when created.
  2. -
  3. -path optional is the path of the Unix Domain Socket File, if not set this will be defaylted to ipc.config.socketRoot+ipc.config.appspace+id
  4. -
  5. -callback optional this is the function to execute when the socket has been created.
  6. -

examples

- -
ipc.connectTo('world');
-
- -

or using just an id and a callback

- -
ipc.connectTo(
-    'world',
-    function(){
-        ipc.of.world.on(
-            'hello',
-            function(data){
-                ipc.log(data.debug); 
-                //if data was a string, it would have the color set to the debug style applied to it
-            }
-        )
-    }
-);
-
- -

or explicitly setting the path

- -
ipc.connectTo(
-    'world',
-    'myapp.world'
-);
-
- -

or explicitly setting the path with callback

- -
ipc.connectTo(
-    'world',
-    'myapp.world',
-    function(){
-        ...
-    }
-);
-
- -
-connectToNet
- -

ipc.connectToNet(id,host,port,callback)

- -

Used to connect as a client to a TCP or TLS socket via the network card. This can be local or remote, if local, it is recommended that you use the Unix Socket Implementaion of connectTo instead as it is much faster since it avoids the network card alltogether.

- -
    -
  1. -id required is the string id of the socket being connected to. For TCP & TLS sockets, this id is added to the ipc.of object when the socket is created with a refrence to the socket.
  2. -
  3. -host optional is the host on which the TCP or TLS socket resides. This will default to ipc.config.networkHost if not specified.
  4. -
  5. -port optional -
  6. -
  7. -callback optional this is the function to execute when the socket has been created.
  8. -

examples arguments can be ommitted solong as they are still in order.
-So while the default is : (id,host,port,callback), the following examples will still work because they are still in order (id,port,callback) or (id,host,callback) or (id,port) etc.

- -
ipc.connectToNet('world');
-
- -

or using just an id and a callback

- -
ipc.connectToNet(
-    'world',
-    function(){
-        ...
-    }
-);
-
- -

or explicitly setting the host and path

- -
ipc.connectToNet(
-    'world',
-    'myapp.com',serve(path,callback)
-    3435
-);
-
- -

or only explicitly setting port and callback

- -
ipc.connectToNet(
-    'world',
-    3435,
-    function(){
-        ...
-    }
-);
-
- -
-serve
- -

ipc.serve(path,callback);

- -

Used to create local Unix Socket Server to which Clients can bind. The server can emit events to specific Client Sockets, or broadcast events to all known Client Sockets.

- -
    -
  1. -path optional This is the Unix Domain Socket path to bind to. If not supplied, it will default to : ipc.config.socketRoot + ipc.config.appspace + ipc.config.id;
  2. -
  3. -

    callback optional This is a function to be called after the Server has started. This can also be done by binding an event to the start event as follows :

    - -

    ipc.server.on( - 'start', - callback -);

    -
  4. -

examples

- -
ipc.serve();
-
- -

or specifying callback

- -
ipc.serve(
-    function(){...}
-);
-
- -

or specify path

- -
ipc.serve(
-    '/tmp/myapp.myservice'
-);
-
- -

or specifying everything

- -
ipc.serve(
-    '/tmp/myapp.myservice',
-    function(){...}
-);
-
- -
-serveNet
- -

coming soon ... -For TCP, TLS & UDP servers this is most likely going to be local host or 0.0.0.0 unless you have something like node-http-server installed to run subdomains for you.

- -

+

Basic Examples

@@ -347,7 +522,7 @@ ipc.serve( 'message', function(data,socket){ ipc.log('got a message : '.debug, data); - socket.emit( + ipc.server.emit( 'message', data+' world!' ); @@ -491,7 +666,17 @@ ipc.server.start(); - + + + diff --git a/params.json b/params.json index 79aaa0e..ce279a0 100644 --- a/params.json +++ b/params.json @@ -1 +1 @@ -{"name":"Node-ipc","tagline":"Inter Process Communication Module for node using Unix sockets and servers. Giving lightning speed by bypassing the network card for local sockets and ipc.","body":"#node-ipc\r\n*a nodejs module for local and remote Inter Process Communication*\r\n\r\n**npm install node-ipc**\r\n\r\n*this is a new project so more documentation will come*\r\n\r\n----\r\n#### Types of IPC Sockets\r\n\r\n| Type | Definition |\r\n|-----------|------------|\r\n|Unix Socket| Gives lightning fast communication and avoids the network card to reduce overhead and latency. [Local Unix Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/unixSocket/ \"Unix Socket Node IPC examples\") |\r\n|TCP Socket | Gives the most reliable communication across the network. Can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because TCP sockets go through the network card while Unix Sockets do not. [Local or remote network TCP Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/TCPSocket/ \"TCP Socket Node IPC examples\") |\r\n|TLS Socket | ***coming soon...*** |\r\n|UDP Sockets| Gives the **fastest network communication**. UDP is less reliable but much faster than TCP. It is best used for streaming non critical data like sound, video, or multiplayer game data as it can drop packets depending on network connectivity and other factors. UDP can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because UDP sockets go through the network card while Unix Sockets do not. [Local or remote network UDP Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/UDPSocket/ \"UDP Socket Node IPC examples\") |\r\n\r\n----\r\n### IPC Default Variables \r\n\r\n``ipc.config`` \r\n\r\nSet these variables in the ``ipc.config`` scope to overwrite or set default values.\r\n\r\n {\r\n appspace : 'app.',\r\n socketRoot : '/tmp/',\r\n id : os.hostname(),\r\n networkHost : 'localhost',\r\n networkPort : 8000,\r\n encoding : 'utf8',\r\n silent : false,\r\n maxConnections : 100,\r\n retry : 500\r\n }\r\n\r\n| variable | documentation |\r\n|----------|---------------|\r\n| appspace | used for Unix Socket (Unix Domain Socket) namespacing. If not set specifically, the Unix Domain Socket will combine the socketRoot, appspace, and id to form the Unix Socket Path for creation or binding. This is available incase you have many apps running on your system, you may have several sockets with the same id, but if you change the appspace, you will still have app specic unique sockets.|\r\n| socketRoot| the directory in which to create or bind to a Unix Socket |\r\n| id | the id of this socket or service |\r\n| networkHost| the local or remote host on which TCP, TLS or UDP Sockets should connect |\r\n| networkPort| the default port on which TCP, TLS, or UDP sockets should connect |\r\n| encoding | the default encoding for data sent on sockets |\r\n| silent | turn on/off logging default is false which means logging is on |\r\n| maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. |\r\n| retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. |\r\n\r\n----\r\n\r\n#### IPC Methods \r\nThese methods are available in the IPC Scope. \r\n\r\n----\r\n##### log\r\n\r\n``ipc.log(a,b,c,d,e...);`` \r\n\r\nipc.log will accept any number of arguments and if ``ipc.config.silent`` is not set, it will concat them all with a sincle space ' ' between them and then log them to the console. This is fast because it prevents any concation from happening if the ipc is set to silent. That way if you leave your logging in place it should not effect performance.\r\n\r\nthe log also supports [colors](https://github.com/Marak/colors.js) implementation. All of the available styles are supported and the theme styles are as follows :\r\n\r\n {\r\n good : 'green',\r\n notice : 'yellow',\r\n warn : 'red',\r\n error : 'redBG',\r\n debug : 'magenta',\r\n variable: 'cyan',\r\n data : 'blue'\r\n } \r\n\r\nYou can override any of these settings by requireing colors and setting the theme as follows :\r\n\r\n var colors=require('colors');\r\n \r\n colors.setTheme(\r\n {\r\n good : 'zebra',\r\n notice : 'redBG',\r\n ...\r\n } \r\n );\r\n----\r\n##### connectTo\r\n\r\n``ipc.connectTo(id,path,callback);`` \r\n\r\nUsed for connecting as a client to local Unix Sockets. ***This is the fastst way for processes on the same machine to communicate*** because it bypasses the network card which TCP and UDP must both use.\r\n\r\n\r\n1. ``id`` ***required*** is the string id of the socket being connected to. The socket with this id is added to the ipc.of object when created.\r\n2. ``path`` ***optional*** is the path of the Unix Domain Socket File, if not set this will be defaylted to ``ipc.config.socketRoot``+``ipc.config.appspace``+``id`` \r\n3. ``callback`` ***optional*** this is the function to execute when the socket has been created.\r\n\r\n**examples**\r\n\r\n ipc.connectTo('world');\r\n \r\nor using just an id and a callback\r\n \r\n ipc.connectTo(\r\n 'world',\r\n function(){\r\n ipc.of.world.on(\r\n 'hello',\r\n function(data){\r\n ipc.log(data.debug); \r\n //if data was a string, it would have the color set to the debug style applied to it\r\n }\r\n )\r\n }\r\n );\r\n\r\nor explicitly setting the path\r\n\r\n ipc.connectTo(\r\n 'world',\r\n 'myapp.world'\r\n );\r\n \r\nor explicitly setting the path with callback\r\n\r\n ipc.connectTo(\r\n 'world',\r\n 'myapp.world',\r\n function(){\r\n ...\r\n }\r\n );\r\n----\r\n##### connectToNet\r\n\r\n``ipc.connectToNet(id,host,port,callback)`` \r\n\r\nUsed to connect as a client to a TCP or TLS socket via the network card. This can be local or remote, if local, it is recommended that you use the Unix Socket Implementaion of ``connectTo`` instead as it is much faster since it avoids the network card alltogether.\r\n\r\n1. ``id`` ***required*** is the string id of the socket being connected to. For TCP & TLS sockets, this id is added to the ``ipc.of`` object when the socket is created with a refrence to the socket.\r\n2. ``host`` ***optional*** is the host on which the TCP or TLS socket resides. This will default to ``ipc.config.networkHost`` if not specified.\r\n3. ``port`` ***optional***\r\n4. ``callback`` ***optional*** this is the function to execute when the socket has been created.\r\n\r\n**examples** arguments can be ommitted solong as they are still in order. \r\nSo while the default is : (id,host,port,callback), the following examples will still work because they are still in order (id,port,callback) or (id,host,callback) or (id,port) etc.\r\n\r\n ipc.connectToNet('world');\r\n \r\nor using just an id and a callback\r\n \r\n ipc.connectToNet(\r\n 'world',\r\n function(){\r\n ...\r\n }\r\n );\r\n\r\nor explicitly setting the host and path\r\n\r\n ipc.connectToNet(\r\n 'world',\r\n 'myapp.com',serve(path,callback)\r\n 3435\r\n );\r\n \r\nor only explicitly setting port and callback\r\n\r\n ipc.connectToNet(\r\n 'world',\r\n 3435,\r\n function(){\r\n ...\r\n }\r\n );\r\n\r\n----\r\n##### serve\r\n\r\n``ipc.serve(path,callback);`` \r\n\r\nUsed to create local Unix Socket Server to which Clients can bind. The server can ``emit`` events to specific Client Sockets, or ``broadcast`` events to all known Client Sockets. \r\n\r\n1. ``path`` ***optional*** This is the Unix Domain Socket path to bind to. If not supplied, it will default to : ipc.config.socketRoot + ipc.config.appspace + ipc.config.id;\r\n2. ``callback`` ***optional*** This is a function to be called after the Server has started. This can also be done by binding an event to the start event as follows :\r\n\r\n ipc.server.on(\r\n 'start',\r\n callback\r\n );\r\n\r\n***examples***\r\n\r\n ipc.serve();\r\n\r\nor specifying callback\r\n\r\n ipc.serve(\r\n function(){...}\r\n );\r\n \r\nor specify path\r\n\r\n ipc.serve(\r\n '/tmp/myapp.myservice'\r\n );\r\n \r\nor specifying everything\r\n\r\n ipc.serve(\r\n '/tmp/myapp.myservice',\r\n function(){...}\r\n );\r\n\r\n---- \r\n##### serveNet\r\ncoming soon ...\r\nFor TCP, TLS & UDP servers this is most likely going to be local host or 0.0.0.0 unless you have something like [node-http-server](https://github.com/RIAEvangelist/node-http-server) installed to run subdomains for you.\r\n\r\n----\r\n### Basic Examples \r\n\r\n#### Server for Unix Sockets & TCP Sockets \r\nThe server is the process keeping a socket for IPC open. Multiple sockets can connect to this server and talk to it. It can also broadcast to all clients or emit to a specific client. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.\r\n\r\n var ipc=require('node-ipc');\r\n\r\n ipc.config.id = 'world';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.serve(\r\n function(){\r\n ipc.server.on(\r\n 'message',\r\n function(data,socket){\r\n ipc.log('got a message : '.debug, data);\r\n socket.emit(\r\n 'message',\r\n data+' world!'\r\n );\r\n }\r\n );\r\n }\r\n );\r\n \r\n ipc.server.start();\r\n\r\n#### Client for Unix Sockets & TCP Sockets \r\nThe client connects to the servers socket for Inter Process Communication. The socket will recieve events emitted to it specifically as well as events which are broadcast out on the socket by the server. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.\r\n\r\n var ipc=require('../../../node-ipc');\r\n\r\n ipc.config.id = 'hello';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.connectTo(\r\n 'world',\r\n function(){\r\n ipc.of.world.on(\r\n 'connect',\r\n function(){\r\n ipc.log('## connected to world ##'.rainbow, ipc.config.delay);\r\n ipc.of.world.emit(\r\n 'message',\r\n 'hello'\r\n )\r\n }\r\n );\r\n ipc.of.world.on(\r\n 'disconnect',\r\n function(){\r\n ipc.log('disconnected from world'.notice);\r\n }\r\n );\r\n ipc.of.world.on(\r\n 'message',\r\n function(data){\r\n ipc.log('got a message from world : '.debug, data);\r\n }\r\n );\r\n }\r\n );\r\n \r\n#### Server & Client for UDP Sockets \r\nUDP Sockets are different than Unix & TCP Sockets because they must be bound to a unique port on their machine to recieve messages. For example, A TCP or Unix Socket client could just connect to a seperate TCP or Unix Socket sever. That client could then exchange, both send and recive, data on the servers port or location. UDP Sockets can not do this. They must bind to a port to recieve or send data. \r\n\r\nThis means a UDP Client and Server are the same thing because inorder to recieve data, a UDP Socket must have its own port to recieve data on, and only one process can use this port at a time. It also means that inorder to ``emit`` or ``broadcast`` data the UDP server will need to know the host and port of the Socket it intends to broadcast the data to.\r\n\r\nThis is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.\r\n\r\n##### UDP Server 1 - \"World\" \r\n\r\n var ipc=require('../../../node-ipc');\r\n\r\n ipc.config.id = 'world';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.serveNet(\r\n 'udp4',\r\n function(){\r\n console.log(123);\r\n ipc.server.on(\r\n 'message',\r\n function(data,socket){\r\n ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable);\r\n ipc.server.emit(\r\n socket,\r\n 'message',\r\n {\r\n from : ipc.config.id,\r\n message : data.message+' world!'\r\n }\r\n );\r\n }\r\n );\r\n \r\n console.log(ipc.server);\r\n }\r\n );\r\n \r\n ipc.server.define.listen.message='This event type listens for message strings as value of data key.';\r\n \r\n ipc.server.start();\r\n \r\n##### UDP Server 2 - \"Hello\"\r\n*note* we set the port here to 8001 because the world server is already using the default ipc.config.networkPort of 8000. So we can not bind to 8000 while world is using it.\r\n\r\n ipc.config.id = 'hello';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.serveNet(\r\n 8001,\r\n 'udp4',\r\n function(){\r\n ipc.server.on(\r\n 'message',\r\n function(data){\r\n ipc.log('got Data');\r\n ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable);\r\n }\r\n );\r\n ipc.server.emit(\r\n {\r\n address : 'localhost',\r\n port : ipc.config.networkPort\r\n },\r\n 'message',\r\n {\r\n from : ipc.config.id,\r\n message : 'Hello'\r\n }\r\n );\r\n }\r\n );\r\n \r\n ipc.server.define.listen.message='This event type listens for message strings as value of data key.';\r\n \r\n ipc.server.start();\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file +{"name":"Node-ipc","tagline":"Inter Process Communication Module for node using Unix sockets and servers. Giving lightning speed by bypassing the network card for local sockets and ipc.","body":"#node-ipc\r\n*a nodejs module for local and remote Inter Process Communication* for Linux, Mac and Windows.\r\n\r\n**npm install node-ipc** \r\n[![alt node-ipc npm details](https://nodei.co/npm/node-ipc.png?stars=true \"node-ipc npm module details \")](https://npmjs.org/package/event-pubsub \"node-ipc details from npm\")\r\n\r\nPackage details websites :\r\n* [GitHub.io site](http://riaevangelist.github.io/node-ipc/ \"node-ipc documentation\"). A prettier version of this site.\r\n* [NPM Module](https://www.npmjs.org/package/node-ipc \"node-ipc npm module\"). The npm page for the node-ipc module.\r\n\r\n\r\n\r\n----\r\n#### Types of IPC Sockets\r\n\r\n| Type | Stability |Definition |\r\n|-----------|-----------|-----------|\r\n|Unix Socket| Stable | Gives Linux and Mac lightning fast communication and avoids the network card to reduce overhead and latency. [Local Unix Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/unixSocket/ \"Unix Socket Node IPC examples\") |\r\n|TCP Socket | Stable | Gives the most reliable communication across the network. Can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because TCP sockets go through the network card while Unix Sockets do not. [Local or remote network TCP Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/TCPSocket/ \"TCP Socket Node IPC examples\") |\r\n|TLS Socket | Alpha | ***coming soon...*** |\r\n|UDP Sockets| Stable | Gives the **fastest network communication**. UDP is less reliable but much faster than TCP. It is best used for streaming non critical data like sound, video, or multiplayer game data as it can drop packets depending on network connectivity and other factors. UDP can be used for local IPC as well, but is slower than #1's Unix Socket Implementation because UDP sockets go through the network card while Unix Sockets do not. [Local or remote network UDP Socket examples ](https://github.com/RIAEvangelist/node-ipc/tree/master/example/UDPSocket/ \"UDP Socket Node IPC examples\") | \r\n\r\n| OS | Supported Sockets |\r\n|-----|--------------------|\r\n|Linux| Unix, TCP, TLS, UDP|\r\n|Mac | Unix, TCP, TLS, UDP|\r\n|Win | TCP, TLS, UDP | \r\n\r\n**Windows** users may want to use UDP servers for the fastest local IPC. Unix Servers are the fastest oprion on Linux and Mac, but not available for windows. \r\n\r\n----\r\n\r\n#### IPC Methods \r\nThese methods are available in the IPC Scope. \r\n\r\n----\r\n##### log\r\n\r\n``ipc.log(a,b,c,d,e...);`` \r\n\r\nipc.log will accept any number of arguments and if ``ipc.config.silent`` is not set, it will concat them all with a sincle space ' ' between them and then log them to the console. This is fast because it prevents any concation from happening if the ipc is set to silent. That way if you leave your logging in place it should not effect performance.\r\n\r\nthe log also supports [colors](https://github.com/Marak/colors.js) implementation. All of the available styles are supported and the theme styles are as follows :\r\n\r\n {\r\n good : 'green',\r\n notice : 'yellow',\r\n warn : 'red',\r\n error : 'redBG',\r\n debug : 'magenta',\r\n variable: 'cyan',\r\n data : 'blue'\r\n } \r\n\r\nYou can override any of these settings by requireing colors and setting the theme as follows :\r\n\r\n var colors=require('colors');\r\n \r\n colors.setTheme(\r\n {\r\n good : 'zebra',\r\n notice : 'redBG',\r\n ...\r\n } \r\n );\r\n----\r\n##### connectTo\r\n\r\n``ipc.connectTo(id,path,callback);`` \r\n\r\nUsed for connecting as a client to local Unix Sockets. ***This is the fastst way for processes on the same machine to communicate*** because it bypasses the network card which TCP and UDP must both use.\r\n\r\n| variable | required | definition |\r\n|----------|----------|------------|\r\n| id | required | is the string id of the socket being connected to. The socket with this id is added to the ipc.of object when created. |\r\n| path | optional | is the path of the Unix Domain Socket File, if not set this will be defaylted to ``ipc.config.socketRoot``+``ipc.config.appspace``+``id`` |\r\n| callback | optional | this is the function to execute when the socket has been created. |\r\n\r\n**examples** arguments can be ommitted solong as they are still in order.\r\n\r\n ipc.connectTo('world');\r\n \r\nor using just an id and a callback\r\n \r\n ipc.connectTo(\r\n 'world',\r\n function(){\r\n ipc.of.world.on(\r\n 'hello',\r\n function(data){\r\n ipc.log(data.debug); \r\n //if data was a string, it would have the color set to the debug style applied to it\r\n }\r\n )\r\n }\r\n );\r\n\r\nor explicitly setting the path\r\n\r\n ipc.connectTo(\r\n 'world',\r\n 'myapp.world'\r\n );\r\n \r\nor explicitly setting the path with callback\r\n\r\n ipc.connectTo(\r\n 'world',\r\n 'myapp.world',\r\n function(){\r\n ...\r\n }\r\n );\r\n----\r\n##### connectToNet\r\n\r\n``ipc.connectToNet(id,host,port,callback)`` \r\n\r\nUsed to connect as a client to a TCP or TLS socket via the network card. This can be local or remote, if local, it is recommended that you use the Unix Socket Implementaion of ``connectTo`` instead as it is much faster since it avoids the network card alltogether.\r\n\r\n| variable | required | definition |\r\n|----------|----------|------------|\r\n| id | required | is the string id of the socket being connected to. For TCP & TLS sockets, this id is added to the ``ipc.of`` object when the socket is created with a refrence to the socket. |\r\n| host | optional | is the host on which the TCP or TLS socket resides. This will default to ``ipc.config.networkHost`` if not specified. |\r\n| port | optional | the port on which the TCP or TLS socket resides. |\r\n| callback | optional | this is the function to execute when the socket has been created. |\r\n\r\n**examples** arguments can be ommitted solong as they are still in order. \r\nSo while the default is : (id,host,port,callback), the following examples will still work because they are still in order (id,port,callback) or (id,host,callback) or (id,port) etc.\r\n\r\n ipc.connectToNet('world');\r\n \r\nor using just an id and a callback\r\n \r\n ipc.connectToNet(\r\n 'world',\r\n function(){\r\n ...\r\n }\r\n );\r\n\r\nor explicitly setting the host and path\r\n\r\n ipc.connectToNet(\r\n 'world',\r\n 'myapp.com',serve(path,callback)\r\n 3435\r\n );\r\n \r\nor only explicitly setting port and callback\r\n\r\n ipc.connectToNet(\r\n 'world',\r\n 3435,\r\n function(){\r\n ...\r\n }\r\n );\r\n\r\n----\r\n##### serve\r\n``ipc.serve(path,callback);`` \r\n\r\nUsed to create local Unix Socket Server to which Clients can bind. The server can ``emit`` events to specific Client Sockets, or ``broadcast`` events to all known Client Sockets. \r\n\r\n| variable | required | definition |\r\n|----------|----------|------------|\r\n| path | optional | This is the Unix Domain Socket path to bind to. If not supplied, it will default to : ipc.config.socketRoot + ipc.config.appspace + ipc.config.id; |\r\n| callback | optional | This is a function to be called after the Server has started. This can also be done by binding an event to the start event like ``ipc.server.on('start',function(){});`` |\r\n\r\n***examples*** arguments can be ommitted solong as they are still in order.\r\n\r\n ipc.serve();\r\n\r\nor specifying callback\r\n\r\n ipc.serve(\r\n function(){...}\r\n );\r\n \r\nor specify path\r\n\r\n ipc.serve(\r\n '/tmp/myapp.myservice'\r\n );\r\n \r\nor specifying everything\r\n\r\n ipc.serve(\r\n '/tmp/myapp.myservice',\r\n function(){...}\r\n );\r\n\r\n---- \r\n##### serveNet\r\n\r\n``serveNet(host,port,UDPType,callback)``\r\n\r\nUsed to create TCP, TLS or UDP Socket Server to which Clients can bind or other servers can send data to. The server can ``emit`` events to specific Client Sockets, or ``broadcast`` events to all known Client Sockets. \r\n\r\n\r\n| variable | required | definition |\r\n|----------|----------|------------|\r\n| host | optional | If not specified this defaults to localhost. For TCP, TLS & UDP servers this is most likely going to be localhost or 0.0.0.0 unless you have something like [node-http-server](https://github.com/RIAEvangelist/node-http-server) installed to run subdomains for you. |\r\n| port | optional | The port on which the TCP, UDP, or TLS Socket server will be bound, this defaults to 8000 if not specified |\r\n| UDPType | optional | If set this will create the server as a UDP socket. 'udp4' or 'udp6' are valid values. This defaults to not being set.\r\n| callback | optional | Function to be called when the server is created |\r\n\r\n***examples*** arguments can be ommitted solong as they are still in order.\r\n\r\ndefault tcp server\r\n\r\n ipc.serveNet();\r\n \r\ndefault udp server\r\n\r\n ipc.serveNet('udp4');\r\n\r\nor specifying TCP server with callback\r\n\r\n ipc.serveNet(\r\n function(){...}\r\n );\r\n \r\nor specifying UDP server with callback\r\n\r\n ipc.serveNet(\r\n 'udp4',\r\n function(){...}\r\n );\r\n \r\nor specify port\r\n\r\n ipc.serveNet(\r\n 3435\r\n );\r\n \r\nor specifying everything TCP\r\n\r\n ipc.serveNet(\r\n 'MyMostAwesomeApp.com',\r\n 3435,\r\n function(){...}\r\n );\r\n\r\nor specifying everything UDP\r\n\r\n ipc.serveNet(\r\n 'MyMostAwesomeApp.com',\r\n 3435,\r\n 'udp4',\r\n function(){...}\r\n );\r\n\r\n----\r\n### IPC Stores and Default Variables \r\n\r\n``ipc.of``\r\n\r\nThis is where socket connection refrences will be stored when connecting to them as a client via the ``ipc.connectTo`` or ``iupc.connectToNet``.\r\n\r\n***example***\r\n \r\n ipc.connectTo(\r\n 'world',\r\n function(){\r\n \r\n ipc.of.world.on(\r\n 'message',\r\n function(data){...}\r\n );\r\n \r\n }\r\n );\r\n\r\n----\r\n\r\n``ipc.config`` \r\n\r\nSet these variables in the ``ipc.config`` scope to overwrite or set default values.\r\n\r\n {\r\n appspace : 'app.',\r\n socketRoot : '/tmp/',\r\n id : os.hostname(),\r\n networkHost : 'localhost',\r\n networkPort : 8000,\r\n encoding : 'utf8',\r\n silent : false,\r\n maxConnections : 100,\r\n retry : 500\r\n }\r\n\r\n| variable | documentation |\r\n|----------|---------------|\r\n| appspace | used for Unix Socket (Unix Domain Socket) namespacing. If not set specifically, the Unix Domain Socket will combine the socketRoot, appspace, and id to form the Unix Socket Path for creation or binding. This is available incase you have many apps running on your system, you may have several sockets with the same id, but if you change the appspace, you will still have app specic unique sockets.|\r\n| socketRoot| the directory in which to create or bind to a Unix Socket |\r\n| id | the id of this socket or service |\r\n| networkHost| the local or remote host on which TCP, TLS or UDP Sockets should connect |\r\n| networkPort| the default port on which TCP, TLS, or UDP sockets should connect |\r\n| encoding | the default encoding for data sent on sockets |\r\n| silent | turn on/off logging default is false which means logging is on |\r\n| maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. |\r\n| retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. |\r\n\r\n----\r\n### Basic Examples \r\n\r\n#### Server for Unix Sockets & TCP Sockets \r\nThe server is the process keeping a socket for IPC open. Multiple sockets can connect to this server and talk to it. It can also broadcast to all clients or emit to a specific client. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.\r\n\r\n var ipc=require('node-ipc');\r\n\r\n ipc.config.id = 'world';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.serve(\r\n function(){\r\n ipc.server.on(\r\n 'message',\r\n function(data,socket){\r\n ipc.log('got a message : '.debug, data);\r\n ipc.server.emit(\r\n 'message',\r\n data+' world!'\r\n );\r\n }\r\n );\r\n }\r\n );\r\n \r\n ipc.server.start();\r\n\r\n#### Client for Unix Sockets & TCP Sockets \r\nThe client connects to the servers socket for Inter Process Communication. The socket will recieve events emitted to it specifically as well as events which are broadcast out on the socket by the server. This is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.\r\n\r\n var ipc=require('../../../node-ipc');\r\n\r\n ipc.config.id = 'hello';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.connectTo(\r\n 'world',\r\n function(){\r\n ipc.of.world.on(\r\n 'connect',\r\n function(){\r\n ipc.log('## connected to world ##'.rainbow, ipc.config.delay);\r\n ipc.of.world.emit(\r\n 'message',\r\n 'hello'\r\n )\r\n }\r\n );\r\n ipc.of.world.on(\r\n 'disconnect',\r\n function(){\r\n ipc.log('disconnected from world'.notice);\r\n }\r\n );\r\n ipc.of.world.on(\r\n 'message',\r\n function(data){\r\n ipc.log('got a message from world : '.debug, data);\r\n }\r\n );\r\n }\r\n );\r\n \r\n#### Server & Client for UDP Sockets \r\nUDP Sockets are different than Unix & TCP Sockets because they must be bound to a unique port on their machine to recieve messages. For example, A TCP or Unix Socket client could just connect to a seperate TCP or Unix Socket sever. That client could then exchange, both send and recive, data on the servers port or location. UDP Sockets can not do this. They must bind to a port to recieve or send data. \r\n\r\nThis means a UDP Client and Server are the same thing because inorder to recieve data, a UDP Socket must have its own port to recieve data on, and only one process can use this port at a time. It also means that inorder to ``emit`` or ``broadcast`` data the UDP server will need to know the host and port of the Socket it intends to broadcast the data to.\r\n\r\nThis is the most basic example which will work for both local Unix Sockets and local or remote network TCP Sockets.\r\n\r\n##### UDP Server 1 - \"World\" \r\n\r\n var ipc=require('../../../node-ipc');\r\n\r\n ipc.config.id = 'world';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.serveNet(\r\n 'udp4',\r\n function(){\r\n console.log(123);\r\n ipc.server.on(\r\n 'message',\r\n function(data,socket){\r\n ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable);\r\n ipc.server.emit(\r\n socket,\r\n 'message',\r\n {\r\n from : ipc.config.id,\r\n message : data.message+' world!'\r\n }\r\n );\r\n }\r\n );\r\n \r\n console.log(ipc.server);\r\n }\r\n );\r\n \r\n ipc.server.define.listen.message='This event type listens for message strings as value of data key.';\r\n \r\n ipc.server.start();\r\n \r\n##### UDP Server 2 - \"Hello\"\r\n*note* we set the port here to 8001 because the world server is already using the default ipc.config.networkPort of 8000. So we can not bind to 8000 while world is using it.\r\n\r\n ipc.config.id = 'hello';\r\n ipc.config.retry= 1500;\r\n \r\n ipc.serveNet(\r\n 8001,\r\n 'udp4',\r\n function(){\r\n ipc.server.on(\r\n 'message',\r\n function(data){\r\n ipc.log('got Data');\r\n ipc.log('got a message from '.debug, data.from.variable ,' : '.debug, data.message.variable);\r\n }\r\n );\r\n ipc.server.emit(\r\n {\r\n address : 'localhost',\r\n port : ipc.config.networkPort\r\n },\r\n 'message',\r\n {\r\n from : ipc.config.id,\r\n message : 'Hello'\r\n }\r\n );\r\n }\r\n );\r\n \r\n ipc.server.define.listen.message='This event type listens for message strings as value of data key.';\r\n \r\n ipc.server.start();\r\n","google":"UA-48524110-1","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file