我可以在heroku上设置socket.io聊天吗? [英] Can I set up socket.io chat on heroku?
问题描述
我有一个简单的socket.io聊天应用程序,我已经上传到新的 Heroku'cedar '堆栈。
现在我几乎可以完成所有工作,但我已经遇到了一个绊脚石。在我的本地主机上,我从客户端打开一个到套接字服务器的连接:
//许多HTML省略
socket = new io.Socket('localhost',{port:8888});
但是在Heroku中,我显然必须用别的东西代替其他值。
我可以从服务器上的进程对象获取端口,如下所示:
port = process.env.PORT || 8888
并将其传递给视图。
但我该用什么替代'localhost'
?
这已经改变到2013年10月,heroku加入了websocket支持:
> https://devcenter.heroku.com/articles/node-websockets使用:
heroku实验室:启用websockets
不要忘记删除:
io.configure(function(){
io.set(transports,[ xhr-polling]);
io.set(polling duration,10);
});
I have a simple socket.io chat application which I've uploaded to one of the new Heroku 'cedar' stacks.
Now I almost have everything working but I've hit one stumbling block. On my localhost, I open a connection to the socket server from the client with:
// lots of HTML omitted
socket = new io.Socket('localhost', {port: 8888});
But on Heroku, I obviously must substitute something else in for these values.
I can get the port from the process object on the server like so:
port = process.env.PORT || 8888
and pass that to the view.
But what do I substitute for 'localhost'
?
This has now changed as of Oct 2013, heroku have added websocket support:
https://devcenter.heroku.com/articles/node-websockets
Use:
heroku labs:enable websockets
To enable websockets and dont forget to remove:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
这篇关于我可以在heroku上设置socket.io聊天吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!