简体   繁体   English

握手后 Websocket 立即断开连接(鳄梨酱)

[英]Websocket disconnects immediately after handshake (guacamole)

Forgive bad formatting as it is my first question on here, and thanks in advance for reading!请原谅格式错误,因为这是我在这里的第一个问题,并提前感谢您的阅读! I am currently writing a remote web application that utilises Apache Guacamole to allow RDP, VNC, and SSH connections.我目前正在编写一个远程 Web 应用程序,它利用 Apache Guacamole 来允许 RDP、VNC 和 SSH 连接。 The components I am using are:我正在使用的组件是:

Django for backend server - API calls (database info) and Guacamole Websocket Transmissions;后端服务器的 Django - API 调用(数据库信息)和 Guacamole Websocket 传输; I am using Pyguacamole with Django consumers to handle Guacamole Server communication;我正在使用 Pyguacamole 和 Django 消费者来处理 Guacamole Server 通信; Reactjs for frontend and proxy; Reactjs 用于前端和代理; Nginx for reverse proxy;用于反向代理的 Nginx; All this is hosted on a Centos Stream 8 vm所有这些都托管在 Centos Stream 8 虚拟机上

Basically, my websocket has trouble communicating through a proxy.基本上,我的 websocket 无法通过代理进行通信。 When I run the application without a proxy (firefox in centos running localhost:3000 directly), the guacamole connection works!当我在没有代理的情况下运行应用程序时(直接运行 localhost:3000 的 centos 中的 firefox),鳄梨酱连接有效! Though this is where the application communicates directly with the Django server on port 8000. What I want is for the react application to proxy websocket communications to port 8000 for me, so my nginx proxy only has to deal with port 3000 for production.虽然这是应用程序在端口 8000 上直接与 Django 服务器通信的地方。我想要的是反应应用程序为我将 websocket 通信代理到端口 8000,所以我的 nginx 代理只需要处理端口 3000 即可进行生产。

Here is the code I have tried for my react proxy (src/setupProxy.js):这是我为我的反应代理(src/setupProxy.js)尝试的代码:

const { createProxyMiddleware } = require('http-proxy-middleware');
let proxy_location = '';

module.exports = function(app) {
    app.use(createProxyMiddleware('/api', { target: 'http://localhost:8000', changeOrigin: true, logLevel: "debug" } ));
    app.use( createProxyMiddleware('/ws', { target: 'ws://localhost:8000' + proxy_location, ws: true, changeOrigin: true, logLebel: "debug" } ));
};

I have also already tried with http://localhost:8000 for the ws target url.我也已经尝试使用 http://localhost:8000 作为 ws 目标 url。 Also, the api proxy works, but I am unsure if the ws proxy works.此外,api 代理有效,但我不确定 ws 代理是否有效。 After making a websocket request, the consumer does a guacamole handshake, but disconnects the websocket before it can send anything back.发出 websocket 请求后,消费者进行鳄梨酱握手,但在 websocket 可以发送回之前断开 websocket。

Also, the HPM output shows that it does try upgrading to websocket, but the client disconnects immediately.此外, HPM 输出显示它确实尝试升级到 websocket,但客户端立即断开连接。

Do let me know if you require more information.如果您需要更多信息,请告诉我。

I managed to find what was wrong, it was a small mistake though I felt the need to update this thread.我设法找到了问题所在,虽然我觉得有必要更新此线程,但这是一个小错误。

Basically, in consumers I used accept() instead of websocket_accept(), receive() instead of websocket_receive(), and so on.基本上,在消费者中,我使用了 accept() 而不是 websocket_accept(),receive() 而不是 websocket_receive(),等等。 Careless mistake on my part, but hope this helps someone out!我粗心的错误,但希望这能帮助别人!

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

相关问题 纱线升级后 React 中的 Websocket 握手错误 - Websocket handshake error in React after yarn upgrade React and Express - 本地主机上 WebSocket 握手期间出错 - React and Express - Error during WebSocket handshake on localhost WebSocket 连接失败。 WebSocket 握手期间出错 - socketjs - WebSocket connection failed. Error during WebSocket handshake - socketjs Metro bundler 在构建后自动在 android 上断开连接 - Metro bundler disconnects automatically on android after build Agora 语音通话在 40 秒后断开 - Agora Voice Call Disconnects after 40 seconds Node.js和React之间的Websocket握手错误 - Websocket handshake Error between Node.js and React WebSocket握手期间出错:意外的响应代码:302 - Error during WebSocket handshake: Unexpected response code: 302 WebSocket 连接到“ws://localhost:8080/”失败:WebSocket 握手期间出错:意外响应代码:404 - WebSocket connection to 'ws://localhost:8080/' failed: Error during WebSocket handshake: Unexpected response code: 404 与'ws://.../socket.io/'的WebSocket连接失败:WebSocket握手期间出错:net :: ERR_CONNECTION_RESET - WebSocket connection to 'ws://…/socket.io/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET 导航后会话存储不可用 - sessionStorage not available immediately after navigate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM