Permalink
Browse files

Merge branch 'refs/heads/clearstream' into buffer

  • Loading branch information...
2 parents 8c35f04 + 9e44b5b commit 05dc22c5781db9cd65b1b82868d9cc5c4c888391 @kilianc committed Jul 11, 2012
View
@@ -1,7 +1,7 @@
REPORTER = spec
test:
- @NODE_ENV=test ./node_modules/.bin/mocha test-mocha/*.test.js $(OPT) --colors --reporter $(REPORTER)
+ @NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js $(OPT) --colors --reporter $(REPORTER)
test-bail:
$(MAKE) test OPT=--bail
View
@@ -1,18 +1,15 @@
-
-var nssocket = require('../lib/nssocket');
+var nss = require('../');
var sockets = [];
-var server = nssocket.createServer(function (socket) {
-
+nss.createServer(function (socket) {
sockets.push(socket);
-
- socket.data('Connecting', function (data) {
- console.log("There are now", sockets.length);
-
- for(var i=0, l=sockets.length; i<l; i++) {
- sockets[i].send('Broadcasting', data);
+ socket.ondata('connecting', function (data) {
+ console.log('There are now', sockets.length);
+ sockets.forEach(function (s) {
+ if (socket !== socket) {
+ s.send('broadcasting', data);
}
- console.dir(data);
});
-
-}).listen(4949);
+ console.dir(data);
+ });
+}).listen(4949);
View
@@ -1,10 +1,8 @@
-var nssocket = require('../lib/nssocket');
-var outbound = new nssocket.NsSocket();
-
-outbound.data('Broadcasting', function (data) {
- console.log(data)
-});
+var nss = require('../');
+var outbound = nss();
-outbound.connect(4949);
-
-outbound.send('Connecting', { "random": Math.random() });
+outbound.on('data::broadcasting', function (data) {
+ console.log(data);
+}).connect(4949, function () {
+ outbound.send('connecting', { 'random' : Math.random() });
+});
View
@@ -1,29 +1,12 @@
var net = require('net'),
- nssocket = require('../lib/nssocket');
+ nss = require('../');
net.createServer(function (socket) {
- //
- // Close the underlying socket after `1000ms`
- //
setTimeout(function () {
socket.destroy();
}, 1000);
}).listen(8345);
-//
-// Create an NsSocket instance with reconnect enabled
-//
-var socket = new nssocket.NsSocket({
- reconnect: true,
- type: 'tcp4',
-});
-
-socket.on('start', function () {
- //
- // The socket will emit this event periodically
- // as it attempts to reconnect
- //
- console.dir('start');
-});
-
-socket.connect(8345);
+nss.createClient({ reconnect: true }).on('start', function () {
+ console.log('start');
+}).connect(8345);
@@ -1,4 +1,4 @@
-var nssocket = require('../lib/nssocket');
+var nss = require('../');
//
// define a simple message protocol as [<type>, <id>] and create some messages that use it.
@@ -7,45 +7,45 @@ var message1 = ['message', 'one'];
var message2 = ['message', 'two'];
//
-// Create an `nssocket` TCP server and tell the server to listen on port `6785`.
+// Create an `nss` TCP server and tell the server to listen on port `6785`.
//
-var server = nssocket.createServer(function (socket) {
+var server = nss.createServer(function (socket) {
//
- // Here `socket` will be an instance of `nssocket.NsSocket`.
+ // Here `socket` will be an instance of `NsSocket`.
// When there is a connection, send `message1` to the socket.
//
socket.send(message1);
//
// listen for `message2` from the connecting socket.
//
- socket.data(message2, function (data) {
+ socket.ondata(message2, function (data) {
//
// If this callback is called, we know that the socket
// speaks our language, we will likely be provided with
// a payload. In this case `{ "foo": "bar" }`.
//
- console.dir(data);
- })
+ console.log(data);
+ });
}).listen(6785);
//
-// Create a new `nssocket` instance and then connect to the server in 1000 miliseconds.
+// Create a new `NsSocket` instance and then connect to the server in 1000 miliseconds.
//
setTimeout(function() {
- var outbound = new nssocket.NsSocket();
+ var outbound = nss();
//
- //
//
- outbound.data(message1, function () {
+ //
+ outbound.ondata(message1, function () {
outbound.send(message2, { "foo": "bar" });
});
outbound.connect(6785);
-
-}, 1000);
+
+}, 1000);
@@ -1,37 +1,34 @@
- var nssocket = require('../lib/nssocket');
+var nss = require('../');
- //
- // Create an `nssocket` TCP server
- //
- var server = nssocket.createServer(function (socket) {
- //
- // Here `socket` will be an instance of `nssocket.NsSocket`.
- //
+//
+// Create an `nss` TCP server
+//
+var server = nss.createServer(function (socket) {
+ //
+ // Here `socket` will be an instance of `NsSocket`.
+ //
- socket.send(['drink', 'rum']);
- socket.send(['drink', 'vodka']);
+ socket.send(['drink', 'rum']);
+ socket.send(['drink', 'vodka']);
- // socket.data(['iam', 'here'], function (data) {
- // //
- // // Good! The socket speaks our language
- // // (i.e. simple 'you::there', 'iam::here' protocol)
- // //
- // // { iam: true, indeedHere: true }
- // //
- // console.dir(data);
- // });
- });
+ // socket.data(['iam', 'here'], function (data) {
+ // //
+ // // Good! The socket speaks our language
+ // // (i.e. simple 'you::there', 'iam::here' protocol)
+ // //
+ // // { iam: true, indeedHere: true }
+ // //
+ // console.dir(data)
+ // })
+});
- //
- // Tell the server to listen on port `6785` and then connect to it
- // using another NsSocket instance.
- //
- server.listen(6785);
+//
+// Tell the server to listen on port `6785` and then connect to it
+// using another NsSocket instance.
+//
+server.listen(6785);
- var outbound = new nssocket.NsSocket();
- outbound.data(['drink', '*'], function () {
- console.log('I can mix a', this.event[2], 'drink');
- //outbound.send(['iam', 'here'], { iam: true, indeedHere: true });
- });
-
- outbound.connect(6785);
+nss().ondata(['drink', '*'], function () {
+ console.log('I can mix a', this.event[2], 'drink');
+ //outbound.send(['iam', 'here'], { iam: true, indeedHere: true })
+}).connect(6785);
View
@@ -1,3 +1,3 @@
-module.exports = process.env.NSSSOCKET_COV
+module.exports = process.env.NSSOCKET_COV
? require('./lib-cov/nssocket')
- : require('./lib/nssocket')
+ : require('./lib/nssocket');
Oops, something went wrong. Retry.

0 comments on commit 05dc22c

Please sign in to comment.