updated formatting and added serve documentation

This commit is contained in:
Brandon Nozaki Miller 2014-02-27 11:20:40 -08:00
parent 75bac2eee9
commit 9693924b5e

View file

@ -8,14 +8,18 @@
---- ----
#### Types of IPC Sockets #### Types of IPC Sockets
1. ``Local IPC`` Uses ***Unix Sockets*** to give lightning fast communication and avoid 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") | Type | Definition |
2. ``IPC over TCP`` Uses ***TCP Sockets*** to give 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") |-----------|------------|
3. ``Remote IPC over TLS`` ***coming soon...*** |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") |
4. ``Remote IPC over UDP`` Uses ***UDP Sockets*** to give 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") |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") |
|TLS Socket | ***coming soon...*** |
|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") |
---- ----
### IPC Default Variables ### IPC Default Variables
``ipc.config`` ``ipc.config``
Set these variables in the ``ipc.config`` scope to overwrite or set default values. Set these variables in the ``ipc.config`` scope to overwrite or set default values.
{ {
@ -30,23 +34,28 @@ Set these variables in the ``ipc.config`` scope to overwrite or set default valu
retry : 500 retry : 500
} }
* ``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. | variable | documentation |
* ``socketRoot`` the directory in which to create or bind to a Unix Socket |----------|---------------|
* ``id`` the id of this socket or service | 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.|
* ``networkHost`` the local or remote host on which TCP, TLS or UDP Sockets should connect | socketRoot| the directory in which to create or bind to a Unix Socket |
* ``networkPort`` the default port on which TCP, TLS, or UDP sockets should connect | id | the id of this socket or service |
* ``encoding`` the default encoding for data sent on sockets | networkHost| the local or remote host on which TCP, TLS or UDP Sockets should connect |
* ``silent`` turn on/off logging default is false which means logging is on | networkPort| the default port on which TCP, TLS, or UDP sockets should connect |
* ``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. | encoding | the default encoding for data sent on sockets |
* ``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. | silent | turn on/off logging default is false which means logging is on |
| maxConnections| this is the max number of connections allowed to a socket. It is currently only being set on Unix Sockets. Other Socket types are using the system defaults. |
| retry | this is the time in milliseconds a client will wait before trying to reconnect to a server if the connection is lost. This does not effect UDP sockets since they do not have a client server relationship like Unix Sockets and TCP Sockets. |
---- ----
#### IPC Methods #### IPC Methods
These methods are available in the IPC Scope. These methods are available in the IPC Scope.
----
##### log ##### log
``ipc.log(a,b,c,d,e...);`` ``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. 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](https://github.com/Marak/colors.js) implementation. All of the available styles are supported and the theme styles are as follows : the log also supports [colors](https://github.com/Marak/colors.js) implementation. All of the available styles are supported and the theme styles are as follows :
@ -72,10 +81,13 @@ You can override any of these settings by requireing colors and setting the them
... ...
} }
); );
----
##### connectTo ##### connectTo
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.
``ipc.connectTo(id,path,callback);`` ``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. 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. ``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`` 2. ``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``
3. ``callback`` ***optional*** this is the function to execute when the socket has been created. 3. ``callback`` ***optional*** this is the function to execute when the socket has been created.
@ -115,10 +127,13 @@ or explicitly setting the path with callback
... ...
} }
); );
----
##### connectToNet ##### connectToNet
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.
``ipc.connectToNet(id,host,port,callback)`` ``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. 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. ``host`` ***optional*** is the host on which the TCP or TLS socket resides. This will default to ``ipc.config.networkHost`` if not specified. 2. ``host`` ***optional*** is the host on which the TCP or TLS socket resides. This will default to ``ipc.config.networkHost`` if not specified.
3. ``port`` ***optional*** 3. ``port`` ***optional***
@ -142,7 +157,7 @@ or explicitly setting the host and path
ipc.connectToNet( ipc.connectToNet(
'world', 'world',
'myapp.com', 'myapp.com',serve(path,callback)
3435 3435
); );
@ -156,9 +171,45 @@ or only explicitly setting port and callback
} }
); );
----
##### serve ##### serve
coming soon ...
``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. ``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
);
***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 ##### serveNet
coming soon ... 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](https://github.com/RIAEvangelist/node-http-server) installed to run subdomains for you. 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](https://github.com/RIAEvangelist/node-http-server) installed to run subdomains for you.