forked from foreversd/nssocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[revert breaking] Revert to 0.3.8+; see foreversd#16.
- Loading branch information
Showing
24 changed files
with
975 additions
and
1,325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,3 @@ npm-debug.log | |
*.out | ||
*.o | ||
*.tmp | ||
coverage.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.