Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close connection for Node.js http.createClient?

Is there something like

remote_client.close()

or

request.close()

for closing the http.createClient connection?

It seems like in some occasions, the socket connection is still hanging there after the "response" event is emitted and properly handled.

like image 430
murvinlai Avatar asked Mar 20 '26 05:03

murvinlai


1 Answers

Upgrade to the latest version of node.js (0.4.8).

The syntax for creating clients has changed. You now have

http.request

Which returns a ClientRequest which you can .end and it gives you a ClientResponse in the callback.

The ClientReponse is just a Readable Stream and you can .destroy a stream

like image 166
Raynos Avatar answered Mar 21 '26 23:03

Raynos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!