Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-url-node

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-url-node - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

test/02_reconnect.js

2

package.json
{
"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);
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc