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 7021335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:26:10+00:00 2026-05-27T23:26:10+00:00

I am implementing a http server for some project. I have an HttpServer object

  • 0

I am implementing a http server for some project.

I have an HttpServer object that I created that contains in it a server (net module)

this server contains allot of info, and i want to pass it as parameter to the callback functions. like you would do with “setTimeout“

var time=setTimeout(function(**a**){do somthing}, 2000, **someObject**);

I tried doing something like that in my code but it does not recognize the parameter I passed as an object

var net = require('net');

function HttpServer(port){
    this.port=port;
}

HttpServer.prototype.start = function (){
    console.log("starting the server");
    this.server = net.createServer(function (socket,server) {
        console.log("my port is: "+server.port)
        socket.on('data',function(dat){  });
                                                 },this);
        //i am trying to send to the createserver callback function
        //the parameter 'this' that actually is an HttpServer
        //and  the callback function secives it as 'server' 
        //when i run the program i get an error that server is
        //undefiend and therefor does not have a member port

    this.server.listen(this.port);
}

var httpserver= new HttpServer(4444);
httpserver.start();

Why it does not recognize the parameter sent?

  • 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-05-27T23:26:11+00:00Added an answer on May 27, 2026 at 11:26 pm
    var net = require('net');
    
    function HttpServer(port){
        this.port=port;
    }
    
    HttpServer.prototype.start = function (){
        console.log("starting the server");
        var that = this;    //Store this to that variable
        this.server = net.createServer(function (socket, server) {
            console.log('Server port is: ' + that.port); // Use that in an anonymous function
            socket.on('data',function(dat){  });
        });
        this.server.listen(this.port);
    
    }
    
    
    var httpserver= new HttpServer(4444);
    httpserver.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a small and fast library implementing an HTTP server in .NET
I'm currently implementing a client application that POST's a file over HTTP and have
I am implementing a WCF Data service that implements the following method: http://debugmode.net/2010/06/13/introduction-to-wcf-data-service-and-odata/ I've
I'm implementing a small HTTP server with Ruby using Mongrel. My code currently looks
I'm implementing a Non-Blocking HTTP server in Java and decided to use pure Java
BOSH (Bidirectional-streams Over Synchronous HTTP) is a sneaky way of implementing 2-way client-server communication
I have been working on implementing a (1) server, (n) worker role servers setup
I am looking at implementing a CouchDB server to provide ad-hoc searching of some
I am implementing a Windows-based web server handling multiple specific HTTP requests from clients
I have a server written to Java to service HTTP requests for various clients.

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.