简体   繁体   中英

node.js http server response socket write event?

Is there a way to control each step of a tcp socket write to know the server side progress of a large sized image data transfer?

At worst, how to alter the main node bin folder to add this event?

Finally, can someone explain to me why the max length of node.js http tcp sockets are 1460?

From the documentation :

socket.write(data, [encoding], [callback])

Sends data on the socket. The second parameter specifies the encoding in the case of a string--it defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory. 'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out - this may not be immediately.

Event: 'drain'

Emitted when the write buffer becomes empty. Can be used to throttle uploads.

See also: the return values of socket.write()

So, you can either specify a callback to be called once the data is flushed, or you can register a "drain" event handler on the socket. This doesn't actually tell you about the progress on the other side, but a properly-implemented server will send appropriate notifications when its queue is full, which will trigger the events on the Node.js side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM