Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:38:42+00:00 2026-06-15T18:38:42+00:00

The following is a simple Node.js tcp server. var net = require(‘net’); var conn

  • 0

The following is a simple Node.js tcp server.

var net = require('net');

var conn = [];

var server = net.createServer(function(client) {//'connection' listener
    var i = conn.push(client) - 1;
    //console.log('[conn',i,']', client.remoteAddress, ':', client.remotePort);
    console.log('[disc]', conn[i].remoteAddress, ':', conn[i].remotePort);

    client.on('end', function() {
        console.log('[disc]', conn[i].remoteAddress, ':', conn[i].remotePort);
    });

    client.on('data', function(msg) {
        console.log('[data]', msg.toString());
    })

    client.write('hello\r\n');
    //client.pipe(client);
});

server.listen(8080);

When a client connects, sends, or disconnects, it will print information about the client. However, only when the client disconnects, it prints undefined rather than the socket info. Example:

[conn] 127.0.0.1 : 52711
[data] 127.0.0.1 : 52711 world!
[disc] undefined : undefined

Why does this happen? Is this because when it is closed the socket is destroyed? I need to know the information regarding the closing socket.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:38:43+00:00Added an answer on June 15, 2026 at 6:38 pm

    A disconnected socket has no remote endpoint, hence no remote address or remote port. The socket isn’t destroyed, it’s just no longer connected. If you need to know the remote address and port after the socket is disconnected, you’ll need to keep track of it yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple http server using Node.js: var http = require('http'); var
I have the following two Node.js files: //test.js var hash=require('./hash'); var sys=require('sys'); hash.hash(asdf,function(param){ sys.puts(param);
I try to run this simple code in node.js: var YUI = require(yui3); YUI.use(function(Y)
I have the following node.js files: //test.js: var hash=require('./hash'); var sys=require('sys'); sys.puts(hash.hash(asdf,asdf)); and //hash.js:
I have the following simple shema: var userSchema = new Schema({ name : String,
I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null)
I'm following a simple ajax>php>mysql example posted here http://openenergymonitor.org/emon/node/107 I can only display information
I have a jsp file with the following <c:forEach var=node items=${tree.children}> <c:set var=currentNode value=${node}
I am messing around in Node.js trying to replicate that simple chat server that
I have the following simple Graph class, where for each Node , I store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.