无法让 socket.io 工作并且总是出错ReferenceError: io is not defined
服务器代码:
express = require('express');
var socket = require('socket.io')
app = express();
var io = socket.listen(app);
app.get('/room', function (req, res) {
res.render('room.ejs')
});
io.sockets.on('connection', function (client) {
console.log('Client connected...')
});
app.listen(process.env.PORT || 17336);
客户端代码:
<script src="localhost:17336/socket.io/socket.io.js"></script>
<script>var socket = io.connect('http://localhost:17336')</script>
这是我网站的目录结构:(
在 WebMatrix 中制作)
Site
|__iisnode
|__node_modules
|__.bin
|__ejs
|__express
|__socket.io
|__public
|__views
|__room.ejs (Client code is here)
|__favicon.ico
|__robots.txt
|__server.js (Server code is here)
|__web.config