On Sun, Feb 12, 2012 at 09:27, Ben. <[email protected]> wrote:
> Hi
>
> Im new to node.js and having problems getting a proper connection
> handling to work. As far as I understand for every request the method
> http.createServer() is called.

No, the server is created only once. You pass a callback to
http.createServer() that's called when a request comes in.

> Within this function I add a request-handler for close and end.
>
> req.connection.addListener('close', function () {
>  clearInterval(sendData);
>  res.end();
> });
> req.connection.addListener('end', function () {
>  clearInterval(sendData);
>  res.end();
> });

Don't attach your listeners to the connection object, attach them to
the request object, i.e.:

  req.on('close', ...);
  req.on('end', ...);

> Afterwards I set the response header and send data like a ping every 2
> seconds like this:
>
> res.writeHead(200, noCacheHeaders);
> sendData = setInterval(function()
> {
>  currentTime = new Date();
>  res.write('\n')
> }, res_interval);
>
> When I start a request now it works, when I end it (pressing escape)
> most of them are cancelled and the close and end handlers are called.
> But if I start a few more and cancel them some requests seem never to
> realize the close or end event and keep sending data forever.

Can you post the complete script? There is not enough context here to
see (or say) what's going on.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to