Permalink
Browse files

semicalypse

  • Loading branch information...
1 parent bc27b5c commit 9e44b5bcbe208082247aa8567d04214a6c80bf77 @kilianc kilianc committed Jul 10, 2012
View
@@ -1,15 +1,15 @@
-var nss = require('../')
+var nss = require('../');
-var sockets = []
+var sockets = [];
nss.createServer(function (socket) {
- sockets.push(socket)
+ sockets.push(socket);
socket.ondata('connecting', function (data) {
- console.log('There are now', sockets.length)
+ console.log('There are now', sockets.length);
sockets.forEach(function (s) {
if (socket !== socket) {
- s.send('broadcasting', data)
+ s.send('broadcasting', data);
}
- })
- console.dir(data)
- })
-}).listen(4949)
+ });
+ console.dir(data);
+ });
+}).listen(4949);
View
@@ -1,8 +1,8 @@
-var nss = require('../')
-var outbound = nss()
+var nss = require('../');
+var outbound = nss();
outbound.on('data::broadcasting', function (data) {
- console.log(data)
+ console.log(data);
}).connect(4949, function () {
- outbound.send('connecting', { 'random' : Math.random() })
-})
+ outbound.send('connecting', { 'random' : Math.random() });
+});
View
@@ -1,12 +1,12 @@
var net = require('net'),
- nss = require('../')
+ nss = require('../');
net.createServer(function (socket) {
setTimeout(function () {
- socket.destroy()
- }, 1000)
-}).listen(8345)
+ socket.destroy();
+ }, 1000);
+}).listen(8345);
nss.createClient({ reconnect: true }).on('start', function () {
- console.log('start')
-}).connect(8345)
+ console.log('start');
+}).connect(8345);
@@ -1,10 +1,10 @@
-var nss = require('../')
+var nss = require('../');
//
// define a simple message protocol as [<type>, <id>] and create some messages that use it.
//
-var message1 = ['message', 'one']
-var message2 = ['message', 'two']
+var message1 = ['message', 'one'];
+var message2 = ['message', 'two'];
//
// Create an `nss` TCP server and tell the server to listen on port `6785`.
@@ -15,7 +15,7 @@ var server = nss.createServer(function (socket) {
// Here `socket` will be an instance of `NsSocket`.
// When there is a connection, send `message1` to the socket.
//
- socket.send(message1)
+ socket.send(message1);
//
// listen for `message2` from the connecting socket.
@@ -27,25 +27,25 @@ var server = nss.createServer(function (socket) {
// speaks our language, we will likely be provided with
// a payload. In this case `{ "foo": "bar" }`.
//
- console.log(data)
- })
+ console.log(data);
+ });
-}).listen(6785)
+}).listen(6785);
//
// Create a new `NsSocket` instance and then connect to the server in 1000 miliseconds.
//
setTimeout(function() {
- var outbound = nss()
+ var outbound = nss();
//
//
//
outbound.ondata(message1, function () {
- outbound.send(message2, { "foo": "bar" })
- })
+ outbound.send(message2, { "foo": "bar" });
+ });
- outbound.connect(6785)
+ outbound.connect(6785);
-}, 1000)
+}, 1000);
@@ -1,34 +1,34 @@
- var nss = require('../')
+var nss = require('../');
- //
- // Create an `nss` TCP server
- //
- var server = nss.createServer(function (socket) {
- //
- // Here `socket` will be an instance of `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);
- nss().ondata(['drink', '*'], function () {
- console.log('I can mix a', this.event[2], 'drink')
- //outbound.send(['iam', 'here'], { iam: true, indeedHere: true })
- }).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.NSSOCKET_COV
? require('./lib-cov/nssocket')
- : require('./lib/nssocket')
+ : require('./lib/nssocket');
View
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 9e44b5b

Please sign in to comment.