Socket.io 连接网址? [英] Socket.io connection url?

查看:38
本文介绍了Socket.io 连接网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当前的设置:

  1. 在端口 80 上运行的 Nodejs 代理(运行 http-reverse-proxy).
  2. 在端口 3000 上运行的 Rails 服务器
  3. 在端口 8888 上运行的 Nodejs Web 服务器

因此任何以/nodejs/开头的请求都将被重定向到 8888 上的 nodejs Web 服务器.

So any request starting with /nodejs/ will be redirected to nodejs web server on 8888.

其他任何内容都将重定向到端口 3000 上的 rails 服务器.

Anything else will be redirected to the rails server on port 3000.

目前 Socket.io 需要 io.connect 的连接 url.

Currently Socket.io requires a connection url for io.connect.

注意 /nodejs/socket.io/socket.io.js 是有效的并返回所需的 socket.io 客户端 js 库.

Note that /nodejs/socket.io/socket.io.js is valid and returns the required socket.io client js library.

但是,我无法在我的服务器上将 connection_url 指定为/nodejs/.

However, I am not able to specify connection_url to /nodejs/ on my server.

我已经尝试了 http://myapp.com/nodejs 和其他变体,但我仍然收到以下网址的 404 错误http://myapp/socket.io/1/?t=1331851089106

I have tried http://myapp.com/nodejs and other variants but I am still getting a 404 error with the following url http://myapp/socket.io/1/?t=1331851089106

推荐答案

从 Socket.io 版本 1 开始,资源已被路径替换.使用:

As of Socket.io version 1, resource has been replaced by path. Use :

var socket = io('http://localhost', {path: '/nodejs/socket.io'});

参见:http://blog.seafuj.com/migrating-to-socketio-1-0

这篇关于Socket.io 连接网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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