无法获取socket.io.js [英] Can't get socket.io.js

查看:176
本文介绍了无法获取socket.io.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上是在一个小项目,我应该重新创建一个绘图多人游戏与node.js,mongoDB,socket.io和画布。



抽屉正在像一个魅力,服务器似乎也很好。我的注册/登录/会话和数据库正常工作,唯一的问题是socket.io。当用户加入游戏室时,他可以看到抽屉和工具,但没有连接。为什么浏览器找不到socket.io.js。



我做了什么:



我验证是否已安装,它是使用npm安装socket.io。
我检查服务器是否启动时,打开服务器:在我的控制台中有socket.io启动。
我检查了我的HTML代码,这里是:

 < script type =text / javascriptsrc = /socket.io/socket.io.js\"></script> 

根据数十亿个教程/ dev网站/帮助主题,这应该是有效的。但不是。当我打开浏览器的控制台时,我得到这个:

  X GET http:// localhost:1337 / socket.io / socket.io.js没有发现。 

我不知道问题在哪里,我无法想像出来,它给了我一个巨大的头痛..所以我在这里。



提前感谢帮助! :)

解决方案

鉴于您的评论中的代码,您没有使用正确的变量来初始化 socket.io



尝试这样:

  var express = require('express'); 
var app = express();
var server = app.listen(1337);
var io = require('socket.io')。listen(server);
...

所以代替 socket.io '听'Express应用程序实例,它应该听什么 app.listen(...)返回(这恰好是一个 http.Server 实例)。


I'm actually working on a little project, where i'm supposed to recreate a drawing multiplayer game with node.js, mongoDB, socket.io and canvas.

The drawer is working like a charm, and the server seems to work well too. I got my register/login/sessions and database up and working, the only problem is socket.io. When an user is joining the game room, he can see the drawer and tools, but no connection. Why ? The browser can't find socket.io.js.

What I did :

I verified if it was installed, it is with npm install socket.io. I checked if the server was starting it when turning the server on : Got "socket.io started" in my console. I checked my HTML code, here it is :

<script type="text/javascript" src="/socket.io/socket.io.js"></script>

According to the billions of tutorials/dev sites/help subjects, this is supposed to work. But it's not. When opening the console of my browser, I got this :

X GET http://localhost:1337/socket.io/socket.io.js NOT FOUND.

I don't know where is the problem, I can't figure this out and it's giving me a huge headache.. So I'm here.

Thanks in advance for helping ! :)

解决方案

Given the code in your comment, you're not using the correct variable for initializing socket.io.

Try this:

var express = require('express');
var app     = express();
var server  = app.listen(1337);
var io      = require('socket.io').listen(server);
...

So instead of having socket.io 'listen' on the Express app instance, it should listen to what app.listen(...) returns (which happens to be an http.Server instance).

这篇关于无法获取socket.io.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆