星期四, 4月 16, 2015

node js tcp socekt end and close different

Good Reference: http://maxogden.com/node-streams.html


end(): Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data. only closes the writing stream of the socket, the remote host can keep his writing stream open and send you data.
destroy(): Ensures that no more I/O activity happens on this socket. Only necessary in case of errors (parse error or so).


Event: 'end'#
Emitted when the other end of the socket sends a FIN packet.

By default (allowHalfOpen == false) the socket will destroy its file descriptor once it has written out its pending write queue. However, by setting allowHalfOpen == true the socket will not automatically end() its side allowing the user to write arbitrary amounts of data, with the caveat that the user is required to end() their side now.

Event: 'error'#
Error object
Emitted when an error occurs. The 'close' event will be called directly following this event.

Event: 'close'#
had_error Boolean true if the socket had a transmission error
Emitted once the socket is fully closed. The argument had_error is a boolean which says if the socket was closed due to a transmission error.

沒有留言: