Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AppFog node.js客户端无法加载socket.io_Node.js_Socket.io_Appfog - Fatal编程技术网

AppFog node.js客户端无法加载socket.io

AppFog node.js客户端无法加载socket.io,node.js,socket.io,appfog,Node.js,Socket.io,Appfog,我刚刚在AppFog上部署了一个node.js站点。当我去的时候,它在本地运行得很好”http://localhost:8080“,但当我在AppFog上找到一个时:我发现以下Chrome控制台错误: XMLHttpRequest cannot load http://localhost:8080/socket.io/1/?t=1357769454152. Origin http://bandwithfriends.aws.af.cm is not allowed by Access-Contr

我刚刚在AppFog上部署了一个node.js站点。当我去的时候,它在本地运行得很好”http://localhost:8080“,但当我在AppFog上找到一个时:我发现以下Chrome控制台错误:

XMLHttpRequest cannot load http://localhost:8080/socket.io/1/?t=1357769454152. Origin http://bandwithfriends.aws.af.cm is not allowed by Access-Control-Allow-Origin.
服务器代码:

var app = require('http').createServer(handler),
    io = require('socket.io').listen(app),
    static = require('node-static'); // for serving files

// This will make all the files in the current folder
// accessible from the web
var fileServer = new static.Server('./');


app.listen(process.env.VCAP_APP_PORT || 8080);

io.configure('development', function(){
  io.set('transports', ['xhr-polling']);
});
var url = 'http://localhost:8080';
var socket = io.connect(url);
客户端代码索引.html: 我包括socket.io,如下所示:

<script src="/socket.io/socket.io.js"></script>

我该如何解决这个问题

客户端和服务器端都是错误的

在客户方面;进行以下更改:

var url = io.connect('http://<your domain name>');
//For example: var url = io.connect('http://shash7.ap01.aws.af.cm');
以上代码取自socket.io站点。他们更改了socket.io在0.9版本中侦听的方式,因此使用上述版本


除此之外,一切看起来都很好。如果您仍然无法解决此问题,请告诉我。

您的客户端和服务器端都是错误的

在客户方面;进行以下更改:

var url = io.connect('http://<your domain name>');
//For example: var url = io.connect('http://shash7.ap01.aws.af.cm');
以上代码取自socket.io站点。他们更改了socket.io在0.9版本中侦听的方式,因此使用上述版本


除此之外,一切看起来都很好。如果您仍然无法解决此问题,请告诉我。

要解决此问题,我只需删除客户端代码上的url即可:

var socket = io.connect();

希望这能帮助其他有同样问题的人

我要做的就是删除客户端代码上的url:

var socket = io.connect();

希望这能帮助其他有同样问题的人

我想出来了,看看我的答案。我一直在寻找一种不用快递就能做到这一点的方法,但是谢谢你的帮助!没有快递?我没看到。我的错。别担心,我还是给了你一票。谢谢你的帮助!我想出来了,看看我的答案。我一直在寻找一种不用快递就能做到这一点的方法,但是谢谢你的帮助!没有快递?我没看到。我的错。别担心,我还是给了你一票。谢谢你的帮助!我遇到了完全相同的问题,
var-app=require('http')中的
handler
是什么。createServer(handler),
我尝试使用您的代码,但没有定义。请确保包含处理函数:函数handler(请求,响应){request.addListener('end',function(){fileServer.service(请求,响应);//这将返回正确的文件});}我遇到了完全相同的问题,
var app=require('http')中的
handler
是什么。createServer(handler),
我尝试使用您的代码,但没有定义。请确保包含处理程序函数:函数处理程序(请求,响应){request.addListener('end',function(){fileServer.service(请求,响应);//这将返回正确的文件});}