我正在尝试连接到套接字io,但没有连接
const express = require('express');
const http = require('http');
const mongoose = require('mongoose');
const app = express();
const port = process.env.PORT || 3000;
var server = http.createServer(app);
var io = require("socket.io")(server);
app.use(express.json());
const DB = "";
io.on("connection",(socket) => {
console.log("connected!");
});
mongoose.connect(DB).then(() => {
console.log("connection successful");
}).catch((err) => console.log("no connection"));
server.listen(port, "0.0.0.0", () => {
console.log(`Server running on port ${port}`);
});
当我启动服务器“连接!“未登录控制台,请帮助。
1条答案
按热度按时间bqjvbblv1#
io.on("connection", ...)
事件仅在socket.io客户端连接到您的服务器时发生。它不是一个启动消息,与您的其他
console.log()
语句不同,因此在www.example.com客户端连接之前您不会看到它socket.io。