控制台日志未使用express和socket.io进行日志记录

时间:2018-11-08 16:07:19

标签: node.js express socket.io

我无法理解Web套接字的工作方式。当我在浏览器中访问http://www.localhost:3010时,在io.on函数中没有看到console.log“连接”。有人可以解释为什么吗?

server.js:

[Windows.UI.Notifications.Management.UserNotificationListener, Windows.UI.Notifications, ContentType = WindowsRuntime]
 $listener = [Windows.UI.Notifications.Management.UserNotificationListener]::Current
 $accessStatus = $listener.GetAccessStatus()

 switch($accessStatus)
 {
   "Allowed" {
     Write-host "Yay! Proceed as normal"
   }
   "Denied" {
     Write-host"Access denied"
   }
   "Unspecified" {
     Write-host "Do something, idk"
   }
 }

app.js:

const app = require("./backend/app")
const http = require('http');
const server = http.createServer(app)
var socketIo = require('socket.io')


server.listen(3010, () => {
    console.log("listening")
})

const io = socketIo(server)


io.on("connection", (socket) => {
    console.log("connection")
    socket.emit("news", {hello: "world"})
})

0 个答案:

没有答案