-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (35 loc) · 1 KB
/
index.js
File metadata and controls
41 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var net = require('net');
var proto = exports.protocol = {
client : require('./lib/client/proto'),
server : require('./lib/server/proto'),
};
exports.createServer = function (domain, cb) {
if (typeof domain === 'function') {
cb = domain;
domain = undefined;
}
return net.createServer(function (stream) {
cb(proto.client(domain, stream));
});
};
exports.connect = function (port, host, cb) {
var args = [].slice.call(arguments).reduce(function (acc, arg) {
acc[typeof arg] = arg;
return acc;
}, {});
var cb = args.function;
var stream;
if (args.string && args.string.match(/^[.\/]/)) {
// unix socket
stream = net.createConnection(args.string);
}
else {
var port = args.number || 25;
var host = args.string || 'localhost';
stream = net.createConnection(port, host);
}
stream.on('connect', function () {
cb(proto.server(stream));
});
return stream;
};