Socket.io在Android chrome 51上不起作用

wkl*_*klm 0 javascript android google-chrome websocket socket.io

Socket.io可以在台式机chrome,chrome和firefox上完美运行,但在chrome(标准版和dev(51)安卓版)上均不能正常运行。

这是我的代码:

index.html:

<script src="/socket.io/socket.io.js"></script>
<script type="text/babel" src="scripts/messenger.js"></script>
Run Code Online (Sandbox Code Playgroud)

messenger.js

var socket = io.connect('localhost:3000');
socket.on('chat message incoming', (msg) =>
        this.incomingMessageHandler(JSON.parse(msg))
    )
socket.emit('chat message outgoing', JSON.stringify(message));
Run Code Online (Sandbox Code Playgroud)

我已经完全按照官方的socket.io教程进行了所有操作。有什么想法吗?

干杯,Wojtek

Daa*_*jer 5

好吧,看来您正在连接localhost:3000,可能未指向手机上的有效NodeJS服务器。尝试将该地址更改为可运行您的应用程序的有效地址。另外,最好将协议(http://)添加到地址中。