简体   繁体   English

如何为基于 Web 的终端设置 sockets

[英]How to setup sockets for a web-based terminal

I'm currently working on a project and want to implement a web-based terminal in the node-red-dashboard.我目前正在做一个项目,想在 node-red-dashboard 中实现一个基于 Web 的终端。 I've already set up xterm and wetty.我已经设置了 xterm 和 wetty。 The problem I got is my small knowledge about sockets.我遇到的问题是我对 sockets 的小知识。 Currently I'm trying to link wetty with xterm but it wont work.目前我正在尝试将 wetty 与 xterm 联系起来,但它不起作用。

<link rel="stylesheet" href="/xterm/css/xterm.css" />
<script src="/xterm/lib/xterm.js"></script>
<script src="/xterm-addon-attach/lib/xterm-addon-attach.js"></script>
<div id="terminal"></div>
<script>
    const socketio = context.global.get("socket.io");
        //const sockett = new nett.Socket('3001');
    const socket1 = io("ws://localhost:3001");
    var term = new Terminal();
    var attachAddon = new AttachAddon(socket1);
    term.loadAddon(attachAddon);
    term.open(document.getElementById('terminal'));
    term.write('Raspberry $ ');
</script>

Wetty is hosted on port 3001 and I want to link it to a node at the same machine. Wetty 托管在端口 3001 上,我想将它链接到同一台机器上的节点。 What am I doing wrong?我究竟做错了什么?

You can't access the context from within a NR Dashboard template node like that, because it's running in the browser not the NR backend.您不能像这样从 NR Dashboard 模板节点中访问上下文,因为它在浏览器中运行,而不是在 NR 后端中运行。

And since the NR Dashboard already uses Socket.IO there should be no need to try and load it again.由于 NR Dashboard 已经使用了 Socket.IO,因此无需再次尝试加载它。

Delete the following line:删除以下行:

const socketio = context.global.get("socket.io");

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

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