Socket.io is not served in /socket.io/socket.io.js

大憨熊 提交于 2019-12-23 19:08:27

问题


i've read the answers here about my problem in node.js, but my problem persists. With socket.io in the server, everything looks ok, but in client side, chrome says: Failed to load resource: the server responded with a status of 404 (Not Found) localhost:3382/socket.io/socket.io.js

var express = require("express");
var http = require("http");
var _io = require("socket.io");

var PORT = 3382;

var app = express();

app.listen(PORT, function(){
console.log("Listening from "+PORT);
});

var server = http.createServer(app);
var io = _io.listen(server);

With jade i have:

script(src='/js/jquery.js')
script(src='/js/chat.js')
script(src="socket.io/socket.io.js")

I have the folder js in a folder static, it works ok. I don't know if it's because the versions (node -v show v0.8.16), how do i see versions of express and socket.io?


回答1:


Read through http://expressjs.com/api.html#app.listen, note how app.listen is defined.

In short: replace app.listen with server.listen.



来源:https://stackoverflow.com/questions/14258349/socket-io-is-not-served-in-socket-io-socket-io-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!