gpt4 book ai didi

node.js http 服务器响应套接字写入事件?

转载 作者:搜寻专家 更新时间:2023-11-01 00:02:39 26 4
gpt4 key购买 nike

有没有办法控制一个tcp socket write的每一步来了解服务器端大尺寸图像数据传输的进度?

最坏的情况下,如何更改主 Node 的bin文件夹以添加此事件?

最后,有人能给我解释一下为什么 node.js http tcp 套接字的最大长度是 1460 吗?

最佳答案

来自documentation :

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

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

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

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

Event: 'drain'

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

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

因此,您可以指定在刷新数据后调用的回调,或者您可以在套接字上注册一个“drain”事件处理程序。这实际上并没有告诉您另一端的进度,但是正确实现的服务器将在其队列已满时发送适当的通知,这将触发 Node.js 端的事件。

关于node.js http 服务器响应套接字写入事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17775500/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com