[英]Can't get socket.io on client side
I'm having a hard time to access socket.io on the client side. 我很难访问客户端上的socket.io。 While searching for the problem I found the following notations:
在搜索问题时,我发现以下符号:
<script src="socket.io.js"></script>
<script src="/socket-lib/socket.io.js"></script>
<script src="/socket.io/socket.io.jss"></script>
<script src="http://localhost:80/socket.io/socket.io.jss"></script>
None of those seems to do the trick. 这些似乎都无法解决问题。 When I call the following in my client HTML file
当我在客户端HTML文件中调用以下内容时
var socket = io.connect('http://localhost');
I always get the error: 我总是得到错误:
ReferenceError: io is not defined [Break On This Error] var socket =
io.connect('http://localhost');
Shouldn't this work "automagically"? 这不应该“自动地”工作吗?
PS: Here's what my server side Script looks like: PS:这是我的服务器端脚本的样子:
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
app.listen(80);
function handler (req, res) {
fs.readFile(__dirname + '/temp.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading temp.html');
}
res.writeHead(200);
res.end(data);
});
}
});
它应该是:
<script src="/socket.io/socket.io.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.