简体   繁体   English

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

[英]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? 有没有办法控制tcp套接字写入的每一步,以了解大型图像数据传输的服务器端进度?

At worst, how to alter the main node bin folder to add this event? 在最坏的情况下,如何更改主节点bin文件夹以添加此事件?

Finally, can someone explain to me why the max length of node.js http tcp sockets are 1460? 最后,有人可以向我解释为什么node.js http tcp套接字的最大长度是1460?

From the documentation : 文档

socket.write(data, [encoding], [callback]) 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. 第二个参数指定字符串的编码 - 默认为UTF8编码。

Returns true if the entire data was flushed successfully to the kernel buffer. 如果将整个数据成功刷新到内核缓冲区,则返回true。 Returns false if all or part of the data was queued in user memory. 如果全部或部分数据在用户内存中排队,则返回false。 'drain' will be emitted when the buffer is again free. 当缓冲区再次释放时,将发出'drain'。

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() 另请参见: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. 因此,您可以指定在刷新数据后调用的回调,也可以在套接字上注册“drain”事件处理程序。 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. 这实际上并没有告诉你另一方面的进展,但正确实现的服务器将在其队列已满时发送适当的通知,这将触发Node.js端的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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