Permalink
Browse files

ready

  • Loading branch information...
dotmaster committed Mar 1, 2011
1 parent 4ef0e56 commit 8d44db64f694fc63bd429197e75ecf005f73451b
Showing with 734 additions and 2 deletions.
  1. +1 −1 .gitmodules
  2. 0 README
  3. +96 −0 README.md
  4. +6 −0 index.js
  5. +74 −0 lib/setup.js
  6. +499 −0 nodeClient.js
  7. +57 −0 nodeTransport.js
  8. +1 −1 node_modules/socket.io
View
@@ -1,3 +1,3 @@
[submodule "node_modules/socket.io"]
path = node_modules/socket.io
- url = https://github.com/LearnBoost/Socket.IO-node.git
+ url = git@github.com:dotmaster/Socket.IO-node.git
View
0 README
No changes.
View
@@ -0,0 +1,96 @@
+Node2Node: Socket.io
+============================================
+
+This module adds a new Transport to Socket.io called "nodeTransport", with which you can make socket.io connections between instances of nodes.
+The way this is done is quite similar to the xhr-multipart transport. There is also a module from [remy](https://github.com/remy) called [Socket.io-node-client](https://github.com/remy/Socket.io-node-client), which depends on webSocket transport.
+
+## Requirements
+
+- a patched version of socket.IO-Node. Unfortunately right now this is not part of the official release yet. I have come up however with an architecture, thats needs nearly no changes to Socket.IO, and have started a pull request. I will update to the official version of socket.io-Node as soon as this modification is in the master tree.
+
+## How to use
+
+To install and run do the following
+
+ git clone https://github.com/dotmaster/node2node-socket.io node2node-socket.io
+ git submodules update --init //this clones the patched version of socket.io
+
+### Implementing it on your project
+
+On the server:
+
+ var http = require('http'),
+ io = require('./path/to/node2node-socket.io'),
+
+ server = http.createServer(function(req, res){
+ // your normal server code
+ res.writeHead(200, {'Content-Type': 'text/html'});
+ res.end('<h1>Hello world</h1>');
+ });
+
+ server.listen(80);
+
+ // socket.io, I choose you
+ var socket = io.listen(server);
+
+ socket.on('connection', function(client){
+ // new client is here!
+ client.on('message', function(){ … })
+ client.on('disconnect', function(){ … })
+ });
+
+On the client:
+
+ io = require('node2node-socket.io')
+
+ var Client = new io.nodeClient('0.0.0.0', 1234);
+ Client.connect(); //is async!! but send requests will buffers up if no connection there yet
+ Client.on('connect', function(){...})
+ Client.on('message', function(client){...})
+ Client.on('disconnect', function(){...})
+
+## Features
+
+NodeClient features a client side heartbeat function, which means that if the server was to hang up the client would get a timeout too and will try to reconnect in an exponantially augmenting time interval until a maximum of retries is reached. Socket.io normally features this only on the server side.
+
+Some more 'error' events are added to the Client Object, so you can subscribe to them. The error Object always has a type and a message field.
+
+Logging can be turned on/off in nodeClient by passing an option to function nodeClient lieke io.nodeClient('0.0.0.0', 1234, {logging: true})
+
+## Modifications to Socket.io
+
+- a static function called addTransport is exposed to the outside world to add new transports to socket.io
+- the Client base class of every transport is exposed to the outside world
+
+## Credits
+
+- Gregor Schwab &lt;greg@synaptic-labs.net&gt; ([dotmaster](http://github.com/dotmaster))
+
+- Guillermo Rauch &lt;guillermo@learnboost.com&gt; ([Guille](http://github.com/guille))
+
+- Arnout Kazemier ([3rd-Eden](http://github.com/3rd-Eden))
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,6 @@
+if (new RegExp('v(\\d)\.(\\d)\.(\\d)').exec(process.version)[2]<4) require(__dirname + "/lib/setup").ext('node_modules');
+module.exports = require('./node_modules/socket.io');
+var Listener = module.exports.Listener;
+var nodeTransport = require('./nodeTransport')
+Listener.addTransport('nodeTransport', nodeTransport)
+module.exports.nodeClient = require ('./nodeClient').nodeClient;
View
@@ -0,0 +1,74 @@
+//Setup.js created by Ben Weaver (http://gist.github.com/508314)
+
+var fs = require('fs'),
+ path = require('path');
+
+exports.app = app;
+exports.lib = lib;
+exports.ext = ext;
+exports.run = run;
+
+
+/// --- Methods
+
+var run = require;
+
+// A shortcut for adding `lib' and `ext' subfolders, then running a
+// main program.
+function app(base, main) {
+ lib(path.join(base, 'lib'));
+ ext(path.join(base, 'ext'));
+ return main ? run(path.join(base, main)) : exports;
+}
+
+// Local libraries
+function lib(folder) {
+ if (exists(folder))
+ require.paths.unshift(folder);
+ return exports;
+}
+
+// Third-party libraries
+function ext(folder) {
+ if (!exists(folder))
+ return exports;
+
+
+
+ fs.readdirSync(folder).forEach(function(name) {
+ var base = path.join(folder, name),
+ linked = false;
+
+ // Pure-JS packages have a `lib' folder with LIBRARY.js files in it.
+ // Packages with C++ bindings will have a `build/default' folder
+ // with LIBRARY.node files in it after running node-waf.
+ [path.join(base, '/build/default'), path.join(base, '/lib')]
+ .forEach(function(folder) {
+ if (exists(folder)) {
+ require.paths.unshift(folder);
+ linked = true;
+ }
+ });
+
+ // If neither `lib' or `build' were found, fallback to linking the
+ // folder itself.
+ //if (!linked)
+ require.paths.unshift(base);
+
+ // Some programmers refer to third-party libraries in a fully-qualified manner.
+ require.paths.unshift(folder);
+ });
+ return exports;
+}
+
+
+/// --- Aux
+
+function exists(filename) {
+ try {
+ fs.statSync(filename);
+ return true;
+ } catch (x) {
+ return false;
+ }
+}
Oops, something went wrong.

0 comments on commit 8d44db6

Please sign in to comment.