stream-url-node
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "stream-url-node", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "http://github.com/gritzko/stream-url-node", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -21,3 +21,4 @@ "use strict"; | ||
server.once('listening', on_listen); | ||
server.on('error', on_error); | ||
server.once('error', on_error); | ||
return server; | ||
} | ||
@@ -27,9 +28,19 @@ | ||
var stream = new net.Socket(options); | ||
var on_connect = function () { | ||
stream.removeListener('error', on_error); | ||
callback(null, stream); | ||
}; | ||
var on_error = function (err) { | ||
stream.removeListener('connect', on_connect); | ||
callback(err, null); | ||
}; | ||
stream.once('connect', on_connect); | ||
stream.once('error', on_error); | ||
stream.connect({ | ||
port: url.port, | ||
host: url.hostname | ||
}, function () { | ||
callback(null, stream); | ||
}); | ||
return stream; | ||
} |
@@ -54,1 +54,42 @@ "use strict"; | ||
}); | ||
tape ('1.C connect fails', function (t) { | ||
var url = 'tcp://localhost:1'; | ||
var stream = su.connect(url, function (err, socket) { | ||
t.equal(err.code, 'ECONNREFUSED', 'Connection refused'); | ||
t.notOk(socket, 'Socket parameter should be null'); | ||
setTimeout(function () { | ||
t.end(); | ||
}, 100); | ||
}); | ||
}); | ||
tape ('1.D connect and disconnect', function (t) { | ||
var port = Math.floor(Math.random()*10000) + 2000; | ||
var url = 'tcp://localhost:' + port; | ||
var tcp_server = su.listen(url, function ready (err, serv) { | ||
t.notOk(err, 'Expect no errors'); | ||
t.equal(serv, tcp_server, 'Callback parameter is the server itself'); | ||
serv.on('connection', function (stream) { | ||
t.pass('New incoming connection received'); | ||
stream.end('something'); | ||
}); | ||
var client = su.connect(url, function (err, sock) { | ||
t.pass('Connection established'); | ||
t.notOk(err, 'Expect no errors'); | ||
t.equal(sock, client, 'Callback parameter is the stream itself'); | ||
sock.on('data', function (data) { | ||
t.equal(data.toString(), 'something'); | ||
}); | ||
sock.on('end', function () { | ||
tcp_server.close(); | ||
setTimeout(function () { | ||
t.end(); | ||
}, 100); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9519
7
198