信息-未处理的socket.io网址

达古尔丹

我正在尝试使用套接字连接到我在本地运行的Node服务器,但是我继续在'info - unhandled socket.io url'服务器端+"XMLHttpRequest cannot load http://localhost:8080/socket.io/?EIO=3&transport=polling&t=1424356590540-0. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access."在chrome上(使用address localhost:8000/index.html

// top six lines of code to see setup
var express = require('express'), 
app = express(), 
http = require('http'),
server = http.createServer(app),
io = require('socket.io').listen(server);

server.listen(8080);

我也在端口8000上使用python SimpleHTTPServer

客户代码是:

var socket = io.connect('http://localhost:8080');

socket.on('connection', function(){
    console.log("connected")
});

使用https://cdn.socket.io/socket.io-1.3.4.js “版本的sockets.io

我假设html是不相关的,因为我没有任何javascript代码(对angular和jquery的引用除外)

意大利苍白啤酒

这是CORS的问题

由于您的网页位于localhost:8000上,而Socket.io服务器位于localhost:8080上(两个不同的端口,所以两个不同的服务器),要允许这两个服务器之间的异步请求,您需要启用CORS。浏览器出于安全原因要求这样做。

您的服务器似乎正在使用Express。由于使用了诸如cors之类的NPM软件包,因此在Express中启用CORS非常容易或者,查看关于SO的一些问题,例如:如何允许CORS?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章