Skip to content

Commit

Permalink
Added capability for creating mqtt clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Rudd committed Jan 11, 2012
1 parent 057107b commit 8423a12
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
File renamed without changes.
20 changes: 15 additions & 5 deletions mqtt.js → lib/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
var net = require('net'),
util = require('util');

var defaultPort = 1883;

var defaultHost = '127.0.0.1';
var Connection = require('./connection');

function Server(listener) {
if (!(this instanceof Server)) return new Server(arguments[0], arguments[1]);
if (!(this instanceof Server)) return new Server(listener);

var self = this;

Expand All @@ -18,14 +16,26 @@ function Server(listener) {
self.on('client', listener);
}

var Connection = require('./connection');
self.on('connection', function(socket) {
self.emit('client', new Connection(socket, self));
});

return this;
}

util.inherits(Server, net.Server);

module.exports.createServer = function(listener) {
return new Server(listener);
};

module.exports.createConnection = function(host, port, callback) {
var socket = net.createConnection(host, port),
client = new Connection(socket, null);

socket.on('connect', function() {
client.emit('connected');
});

return client;
}
File renamed without changes.
1 change: 0 additions & 1 deletion protocol.js → lib/protocol.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* Generic */

var protocol = module.exports;

module.exports.types = {
Expand Down

0 comments on commit 8423a12

Please sign in to comment.