Node.JS:将 tcp 转换为 stdin/stdout

发布于 2024-11-26 12:22:29 字数 761 浏览 1 评论 0原文

Node.JS 实时更新代码的能力和自动隔离异常的能力似乎有限。这两者在 Java 中实际上都是默认的。

实时更新的一种非常有效的方法是使用一个侦听器进程来简单地回显与子进程之间的通信。然后为了更新,侦听器启动一个新的子级(它自动读取更新的代码),然后开始向新的子级发送请求,当所有请求完成时结束旧的子级。

  • 是否已经有一个系统通过 stdout/stdin 提供此 http 功能。
  • 是否有系统通过 stdout/stdin 提供 TCP 服务器或 UDP 服务器功能。

我的意思是,提供一个看起来像 httpnet 模块的模块,但它使用 stdout/stdin 作为底层 I/O。

类似于这个CGI模块

某些应用程序只需将 require('http') 更改为 require('cgi')

我打算做类似的事情。我希望重用已经存在的代码,并且还可以轻松地将小型或单一用途的网络服务器转换为运行许多网络应用程序的监听器层。正确进行清理非常重要。应释放结束或错误的连接,并且应正确地双向回显结束/错误事件/命令。

(我相信一种常见的方法是让孩子监听端口,让父母与这些端口进行通信,但我认为 stdout/stdin 解决方案会更有效)

Node.JS seems limited in its ability to live-update code and in its ability to automatically isolate exceptions. Both of which are practically by default in Java.

One very effective way to live-update is to have a listener process that simply echos communication to/from the child process. Then to update, the listener starts up a new child (which reads the updated code automatically) and then starts sending requests to the new child,, ending the old child when all requests are complete.

  • Is there already a system that provides this http functionality through stdout/stdin.
  • Is there a system that provides TCP server or UDP server functionaility through stdout/stdin.

By this I mean, providing a module that looks like the http or net module with the exception that it uses stdout/stdin for the underlying I/O.

Similar to This CGI module

some applications will only have to change require('http') to require('cgi')

I intend to do something similar. I hope to re-use code if it is already out there, and also to easily convert a small or single purpose webserver, into this listener layer which runs many webapps. It is important that cleanup occurs properly. Connections that end or error should be freed up and the end/error events/commands should be properly echoed both ways.

(I believe a common way is to have the children listen on ports and the parent communicate with those ports, but I think an stdout/stdin solution will be more efficient)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清秋悲枫 2024-12-03 12:22:29

使用 nginx (HttpUpstreamModule) 或 HAProxy。在这两种情况下,您都会在前面运行它们并将后端标记为关闭,然后在需要进行实时升级时将其恢复。

Use nginx (HttpUpstreamModule) or HAProxy. In both cases you'd run them in front and mark a backend as down and then bring it back up when you need to do a live upgrade.

空‖城人不在 2024-12-03 12:22:29

我不确定这就是你要找的(事实上,我不确定我是否理解你的问题),但是 Remy Sharp 编写了一个非常有用的节点模块,名为 nodemon。它承诺“监视 Node.js 应用程序中的任何更改并自动重新启动服务器”。这可能有助于解决实时更新代码的问题。

I'm not certain that this is what you're looking for (indeed, I'm not certain that I understand your question), but Remy Sharp has written a very helpful node module called nodemon. It promises to "monitor for any changes in your node.js application and automatically restart the server." This may help with the issue of live updating code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文