Skip to content

Commit

Permalink
[revert breaking] Revert to 0.3.8+; see foreversd#16.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Apr 21, 2013
1 parent 90477ec commit 1588fb2
Show file tree
Hide file tree
Showing 24 changed files with 975 additions and 1,325 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ npm-debug.log
*.out
*.o
*.tmp
coverage.html
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
node_js:
- 0.8
- 0.4
- 0.6
- 0.7

notifications:
email:
Expand Down
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

27 changes: 13 additions & 14 deletions examples/bla.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
var nss = require('../');

var nssocket = require('../lib/nssocket');

var sockets = [];
var server = nssocket.createServer(function (socket) {

sockets.push(socket);

//
// Server code for foo.js to connect to
//
nss.createServer(function (socket) {
sockets.push(socket);
socket.ondata('connecting', function (data) {
console.log('There are now', sockets.length);
sockets.forEach(function (s) {
if (socket !== socket) {
s.send('broadcasting', data);
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);
}
console.dir(data);
});
console.dir(data);
});
}).listen(4949);

}).listen(4949);
22 changes: 9 additions & 13 deletions examples/foo.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
var nss = require('../');
var outbound = nss();
var nssocket = require('../lib/nssocket');
var outbound = new nssocket.NsSocket();

outbound.data('Broadcasting', function (data) {
console.log(data)
});

//
// Example to connect to bla.js
//
outbound
.on('data::broadcasting', function (data) {
console.log(data);
})
.connect(4949, function () {
outbound.send('connecting', { 'random' : Math.random()
});
});
outbound.connect(4949);

outbound.send('Connecting', { "random": Math.random() });
25 changes: 21 additions & 4 deletions examples/reconnect.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
var net = require('net'),
nss = require('../');
nssocket = require('../lib/nssocket');

net.createServer(function (socket) {
//
// Close the underlying socket after `1000ms`
//
setTimeout(function () {
socket.destroy();
}, 1000);
}).listen(8345);

nss.createClient({ reconnect: true }).on('start', function () {
console.log('start');
}).connect(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);
26 changes: 13 additions & 13 deletions examples/simple-protocol.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var nss = require('../');
var nssocket = require('../lib/nssocket');

//
// define a simple message protocol as [<type>, <id>] and create some messages that use it.
Expand All @@ -7,45 +7,45 @@ var message1 = ['message', 'one'];
var message2 = ['message', 'two'];

//
// Create an `nss` TCP server and tell the server to listen on port `6785`.
// Create an `nssocket` TCP server and tell the server to listen on port `6785`.
//
var server = nss.createServer(function (socket) {
var server = nssocket.createServer(function (socket) {

//
// Here `socket` will be an instance of `NsSocket`.
// Here `socket` will be an instance of `nssocket.NsSocket`.
// When there is a connection, send `message1` to the socket.
//
socket.send(message1);

//
// listen for `message2` from the connecting socket.
//
socket.ondata(message2, function (data) {
socket.data(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.log(data);
});
console.dir(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 = nss();
var outbound = new nssocket.NsSocket();

//
//
//
//
outbound.ondata(message1, function () {
outbound.data(message1, function () {
outbound.send(message2, { "foo": "bar" });
});

outbound.connect(6785);

}, 1000);
}, 1000);
61 changes: 32 additions & 29 deletions examples/verbose-protocol.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
var nss = require('../');
var nssocket = require('../lib/nssocket');

//
// Create an `nss` TCP server
//
var server = nss.createServer(function (socket) {
//
// Here `socket` will be an instance of `NsSocket`.
//
//
// Create an `nssocket` TCP server
//
var server = nssocket.createServer(function (socket) {
//
// Here `socket` will be an instance of `nssocket.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);

nss().ondata(['drink', '*'], function () {
console.log('I can mix a', this.event[2], 'drink');
//outbound.send(['iam', 'here'], { iam: true, indeedHere: true })
}).connect(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);
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

Loading

0 comments on commit 1588fb2

Please sign in to comment.