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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:52+00:00 2026-06-17T09:06:52+00:00

I am writing a little dynamic HTTP server based on net module (homework assignment)

  • 0

I am writing a little dynamic HTTP server based on net module (homework assignment) that sends 408 response if the server user didn’t call response.end() after two seconds.

No matter what I tried, the function is not invoked. Here’s another code that demonstrates what I tried to do in my program:

var NET = require("net"); 
var server = NET.createServer(function(socket){
    console.log("In connectionHandler");
    socket.on('data',function(data) {
        console.log("New data");
        var timer = setTimeout(function(end){
            console.log("INSIDE TIMEOUT FUNCTION");
            if (end) {
                return;
            }
            throw new ERROR.ServerError('408',' Request Timeout','The \
            server has timedouted');
            },10,true);
        for (var t = 0 ; t < 100000000000 ; t++){}
        clearTimeout(timer);
    })

});


server.listen(4000, function() {
    console.log("server bound");
});

So, timeout is set to 10 ms followed by a very long loop, yet this doesn’t work.

Why this is happening?

  • 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-17T09:06:53+00:00Added an answer on June 17, 2026 at 9:06 am

    The callback is never called because setTimeout is asynchronous. The timer gets activated when this “turn” is over, and you clear the timeout before the end of the turn.

    You should read first about javascript’s event driven architecture. This tutorisal would be a good start. This is essential to solve your timeout problem.

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

Sidebar

Related Questions

I am writing a little ASP.NET MVC3 app that I am running on Mac
I amm writing a little python script that will grab information from VMs of
I'm writing a little genetic algorithm in Java, as a school assignment. Up until
I'm writing a little wrapper for an application that uses files as arguments. The
On a regular basis I find myself writing little utility programs that use some
Im writing little widget that shows time, date.. with many settings. And I want
I am writing this little python program that will get new posts on the
I'm writing a little command line todo app that has a general git-like interface.
I'm writing a little script that allows me to import my Facebook contacts' email
I'm writing a little thing for an assignment, and I have to manage TCP

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.