客户端正在使用以下方法连接到我的服务器…
var socket = io.connect('http://localhost:52805');
在服务器上,我使用…
// Establish a connection with a WebSocket.
io.on("connection", socket => {
console.log("Socket Connection");
...
现在,如果我检查服务器端的控制台,在控制台中,我会定期得到以下内容…
Socket Connection
Socket Connection
Socket Connection
Socket Connection
...
它一直在打印
插座连接
即使我没有刷新客户。
这是什么原因造成的?这是正常现象吗?如果没有,我该怎么做才能防止这种情况发生?客户端继续轮询服务器是否正常?
编辑
作为附加说明,我正在使用
插座
作为插件
HAPI. JS
…
const sockets = require("./src/Playlist/index");
// Define the server.
const server = new Hapi.Server({
port: process.env.PORT,
routes: {
cors: true
}
});
// Socket.io plugin.
await server.register(sockets);
// Start the server.
await server.start();
在哪里?
sockets
只是一个参考
io.on("connection")
以上提到。