OpenFire服务器不适用于websockets

问题描述 投票:0回答:2

我无法通过WebSocket使用OpenFire服务器。这是我用来连接服务器的代码客户端:

    var ws = new WebSocket('ws://35.228.94.32:7070/ws-xmpp');

    ws.onopen = () => {
        // connection opened
        console.log('open')
    };

    ws.onmessage = (e) => {
        // a message was received
        console.log(e.data);
    };

    ws.onerror = (e) => {
        // an error occurred
        console.log("Error occured", e, e.message);
    };

    ws.onclose = (e) => {
        // connection closed
        console.log("Closing: ", e);
    };

这是我收到的错误:

发生错误{“ isTrusted”:错误,“消息”:“无法连接到从/192.168.232.2(端口54028)之后的/35.228.94.32(端口7070)10000ms“}无法从以下位置连接到/35.228.94.32(端口7070)/192.168.232.2(端口54028),在10000毫秒后

关闭:{“ isTrusted”:否,“ message”:“无法连接到从/192.168.232.2(端口54028)之后的/35.228.94.32(端口7070)10000ms“}

我认为这是带有Websockets的OpenFire的问题,因为如果我尝试使用xmpp协议,它将起作用。你能帮我吗?

node.js websocket xmpp openfire
2个回答
1
投票

您的端点似乎不正确。请尝试以下方法:

ws://35.228.94.32:7070/ws

可选,如果要使用加密,请使用:

wss://35.228.94.32:7443/ws

您将需要设置适当的证书才能正常工作。


0
投票

我已经发现了问题,它与OpenFire无关。我在Google Cloud机器上运行OpenFire,默认情况下,Google使用防火墙阻止传入的请求。因此,允许请求到端口7070,它可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.