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

  • SEARCH
  • Home
  • 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 8106441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:28:05+00:00 2026-06-06T00:28:05+00:00

I am building a simple echo server for the purposes of learning the fundamentals

  • 0

I am building a simple echo server for the purposes of learning the fundamentals about building tcp services with node.js and figuring out what information is available.

When I am creating a server, as shown below, I can access information about the incomingSocket such as the remote address. Why is it that I cannot access the information on the closing of socket? Below is my code; my comment indicates the output I have received.

var net = require ( 'net' );
var server = net.createServer (
    function ( incomingSocket )
    {
        //'connection' listener
        console.log ( 'Connection from ' + incomingSocket.remoteAddress + ':' + incomingSocket.remotePort + " established." );

        incomingSocket.on (
            'data' ,
            function ( data )
            {
                // The incomingSocket.remoteAddress is defined here
                console.log ( incomingSocket.remoteAddress + ':' + incomingSocket.remotePort + ' -> ' + data.toString () );
            }
        );

        incomingSocket.on (
            'close' ,
            function ()
            {
                // The incomingSocket.remoteAddress is undefined here
                console.log ( 'connection from ' + incomingSocket.remoteAddress + ' closed.' );
            }
        );
        incomingSocket.pipe ( incomingSocket );
    }
);
// listening to a port happens here

I would appreciate any response! Thank you!

  • 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-06T00:28:07+00:00Added an answer on June 6, 2026 at 12:28 am

    Well no, because when it gets in the event handler for the socket close event, the socket object no longer exists. If you need to display the remote address of the client as the socket is closing, simply store the remote address as the client initially connects.

    var clients = new Array();
    
    net.createServer(function(socket) {
       var remoteAddress = socket.remoteAddress;
       var remotePort = socket.remotePort;
    
       // Add to array of clients
       clients.push(remoteAddress + ':' + remotePort);
    
       console.log('Connection from ' + remoteAddress  + ':' + remotePort + " established.");
    
       socket.on('data', function(data) {
          console.log(remoteAddress + ':' + remotePort + ' -> ' + data.toString());
       });
    
       socket.on('close', function() {
          // Remove from array of clients
          clients.splice(clients.indexOf(remoteAddress + ':' + remotePort), 1);
    
          console.log('Connection from ' + remoteAddress + ':' + remotePort + ' closed.');
       });
    
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a really simple groupon like script for learning purposes now in
I'm building a simple user registration and information update forms which have a lot
By following example from em-websocket gem, I've just create simple echo-server that running with
I am building simple notificiation system and I just wanted to know what is
Im building a simple chat client which is only supposed to be able to
I'm building a simple availability calendar with PHP and MySQL. I have a table
I am building a simple Point of Sale system for my project. This system
I'm building a simple contact form for a website. It does not connect to
I'm building a simple web application in tornado.web using mongodb as the backend. 90%
I am building a simple particle system and want to use a single array

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.