GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Socket connects and gets data from non-existing service · Issue #2927 · nodejs/node Closed Labels netIssues and PRs related to the net subsystem. DescriptionThe following program tries to connect to a TCP service on "localhost". I do not have a service running at port 4096, so it continuously gets ECONNREFUSED, as expected. However, if you let it run long enough (a couple of minutes on my machine), eventually it does connect, sends data and even receives data, which appears to be the same data as was send. Any ideas what is going on? It seems this only happens with "localhost" and with higher numbered ports For example, it does not show this behaviour when I try and connect to port 7 (which is also not available on my machine). This is with Node.js v0.12.7 and Linux 2.6.32-504.el6.x86_64. /*jslint node:true*/ "use strict"; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith if (!String.prototype.endsWith) { String.prototype.endsWith = function(searchString, position) { var subjectString = this.toString(); if (position === undefined || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; } var net = require("net"); var SERVICE_PORT = 4096; var SERVICE_HOST = "localhost"; function send(req) { var service = new net.Socket(); service.on("connect", function () { console.log("Connected"); service.setEncoding("utf8"); service.end(req); }); var line = ""; service.on("data", function (data) { line += data; if (line.endsWith("\n")) { console.log("Got response [%s]", line.trim()); } }); service.on("error", function (err) { console.error(err); }); service.on("close", function (had_error) { if (had_error) { console.log("Connection closed WITH ERROR"); send(req); // Try again. } else { console.log("Connection closed WITH SUCCESS"); } }); service.connect(SERVICE_PORT, SERVICE_HOST); } send("PING\n"); Example output (last few lines): Activity
MetadataMetadataAssigneesLabelsnetIssues and PRs related to the net subsystem. TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |