发表文章

[Javascript] 远程 websocket 访问 "Remote websocket access"[adonis-framework]

MaTiUs77 8月前 48

你好,

Im 有阿多尼斯运行与此环境保护 HOST=localhost PORT=8081 在我的服务器上的主机 ' ProductionServer '

下一个客户端代码工作正常。

            const io = ws('http://localhost :8081', {});
            const client = io.channel('servermonitor')
            client.connect(function (error, connected) {
                if (error) {
                    console.log(error);
                    return
                }
                console.log('ServerMonitor Connected');
            });

当我尝试使用远程视图进行连接时, 出现此问题的原因是相同的代码, 但更改了主机。

const io = ws('http://ProductionServer:8081', {});

console.log 返回此错误

/servermonitor "无效的命名空间"

有人能我吗?

原文:

Hello,

Im have adonis running with this env HOST=localhost PORT=8081 on my server with the host 'ProductionServer'

The next client code is working good.

            const io = ws('http://localhost :8081', {});
            const client = io.channel('servermonitor')
            client.connect(function (error, connected) {
                if (error) {
                    console.log(error);
                    return
                }
                console.log('ServerMonitor Connected');
            });

The problem appears when i try to connect with a remote view, is the same code but changing the host..

const io = ws('http://ProductionServer:8081', {});

The console.log returns this error

/servermonitor,"Invalid namespace"

Can someone helpme with this please?

相关推荐
最新评论 (5)
thetutlage 8月前
1

你可以通过在浏览器中打开相同的 http://ProductionServer:8081 来达到你的网站吗?

原文:

Can u reach your website as http://ProductionServer:8081 by opening same in the browser?

MaTiUs77 8月前
2

在服务器上, 在运行多尼斯, 我试图访问浏览器 http://localhost:8081 , 并出现了多尼斯前视图, 然后在我尝试访问的同一台计算机上 http://ProductionServer:8081 , 并显示 ERR_CONNECTION_REFUSED 试图从远程视图访问相同的错误

注意: 服务器安装了 wamp 服务器, 因此 localhost:80 和 ProductionServer:80 正在工作。主机正在响应

原文:

In the server, where is running adonis, i attempting to access to the browser http://localhost:8081 and appears the adonis front view, then in the same machine i try to access to http://ProductionServer:8081 and appears ERR_CONNECTION_REFUSED the same error trying to access from a remote view

Note: The server have a wamp server installed, so localhost:80 and ProductionServer:80 is working. The host is responding

MaTiUs77 8月前
3

我改变了现在的环境保护配置HOST=ProductionServer PORT=8081
ProducitonServer:8081 的浏览器正在工作,
客户端 const io = ws('http://ProductionServer:8081', {}); 返回/servermonitor,"Invalid namespace"

但与 HOST = localhost 工作所有好

: S

原文:

i change the env configuration now is HOST=ProductionServer PORT=8081
The browser at ProducitonServer:8081 is working,
the client to const io = ws('http://ProductionServer:8081', {}); returns /servermonitor,"Invalid namespace"

but with HOST = localhost works all good

:S

thetutlage 8月前
4

在服务器内部是否有相同的 channel socket.js 文件?

原文:

Do you have the same channel on the server inside socket.js file?

MaTiUs77 8月前
5

这是我所拥有的, 并像一个魅力

服务器端
env

HOST=localhost
PORT=8081
const Ws = use('Ws');
Ws.channel('/servermonitor', 'ServerMonitorController')

'use strict'
class ServerMonitorController {
	constructor (socket,request) {
		this.socket = socket;
		this.socket = request;		
		console.log("ServerMonitor client connected",socket.id);		
	}
		
	disconnected(socket) {
		console.log("ServerMonitor client disconnected",socket.id);
	}
}

module.exports = ServerMonitorController;

客户端

<script src="https://unpkg.com/adonis-websocket-client/dist/ws.min.js"></script>
<script>
const io = ws('localhost:8081', {});

const client = io.channel('servermonitor')
client.connect(function (error, connected) {
	if (error) {
		console.log(error);
		return
	}
	console.log('ServerMonitor Connected');
});

client.on('disconnect',function(){
	console.log('ServerMonitor Disconnected');
});
</script>

在浏览器上运行 websockets 返回ServerMonitor Connected
只有当浏览器 url 与在. 中定义的主机匹配时, 服务器端才能正常工作。

浏览器测试

现在, 将环境保护主机更改为 ProductionServerconst io = ws('ProductionServer:8081', {});

浏览器测试

Websockets 未连接, 返回

/servermonitor "无效的命名空间"

同样的例子是运行在 sailsjs 和工作, 美男子是非常好的, 我只需要解决这个问题

:(

原文:

This what i have, and works like a charm

SERVER SIDE
ENV

HOST=localhost
PORT=8081
const Ws = use('Ws');
Ws.channel('/servermonitor', 'ServerMonitorController')

'use strict'
class ServerMonitorController {
	constructor (socket,request) {
		this.socket = socket;
		this.socket = request;		
		console.log("ServerMonitor client connected",socket.id);		
	}
		
	disconnected(socket) {
		console.log("ServerMonitor client disconnected",socket.id);
	}
}

module.exports = ServerMonitorController;

CLIENT SIDE

<script src="https://unpkg.com/adonis-websocket-client/dist/ws.min.js"></script>
<script>
const io = ws('localhost:8081', {});

const client = io.channel('servermonitor')
client.connect(function (error, connected) {
	if (error) {
		console.log(error);
		return
	}
	console.log('ServerMonitor Connected');
});

client.on('disconnect',function(){
	console.log('ServerMonitor Disconnected');
});
</script>

Running on browser the websockets returns ServerMonitor Connected
The server side is working good only when the browser url match with the HOST defined in .env.

Browser test

Now changing env HOST to ProductionServer andconst io = ws('ProductionServer:8081', {});

Browser test

Websockets is not connected, returns

/servermonitor,"Invalid namespace"

The same example is running on sailsjs and works, adonis is very good, i need only solve this issue

:(

返回
发表文章
MaTiUs77
文章数
1
评论数
3
注册排名
93357