如何通过 DDP (WebSocket) 协议访问meteor.com 上托管的应用程序? [英] How to access app hosted on meteor.com by DDP (WebSocket) protocol?

查看:15
本文介绍了如何通过 DDP (WebSocket) 协议访问meteor.com 上托管的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Meteor 应用 A 和另一个应用 B,不使用 Meteor,而是与应用程序 A 进行一些数据交换.当我在本地网络中的一台机器上启动 A 时它工作正常,但是当我将它部署在meteor.com 托管上时它没有.服务器没有回复.

I have a Meteor app A and another application B, not using Meteor, but making some data exchange with the app A. It works fine when I launch A on a machine in my local network, but when I deploy it on meteor.com hosting it doesn't. Server doesn't reply.

B 使用代码 new WebSocket("ws://" + host + ":3000/websocket") 进行连接(DDP 协议).但是,当我将 ws 更改为 wss 时,即使使用 LAN 中的机器,它也不再起作用 - 它不回复.

B uses code new WebSocket("ws://" + host + ":3000/websocket") for connection (DDP protocol). But when I change ws to wss it doesn't work any more even with the machine in LAN - it doesn't reply.

当我在浏览器中打开应用程序 A 时,我看到它的主页使用了像

I saw that main page of app A when I open it in browser uses URLs like

wss://ddp--6774-{我的主机名}.meteor.com/sockjs/465/asf0b7da/websocket.

问题:

  1. 如何让 B 使用安全的 WebSocket (wss) 进行连接?

  1. How can I make B to use secure WebSocket (wss) for connection?

如何将其连接到托管在 {my host name}.meteor.com 上的 A?

How can I make connect it to A hosted on {my host name}.meteor.com?

如何强制A使用固定URL回复请求,例如ws://{我的主机名}.meteor.com:3000/websocket ?如何强制它使用 ws 而不是 wss?

How can force A to reply to requests using fixed URL, for example, ws://{my host name}.meteor.com:3000/websocket ? How can I force it to use ws instead of wss?

我应该在 config.js 还是 settings.js 中指定一些东西?

Should I specify something in config.js or settings.js?

有没有办法为meteor.com托管指定环境变量,例如DDP_DEFAULT_CONNECTION_URL、NODE_OPTIONS?

Is there any way to specify environment variables for meteor.com hosting, for example, DDP_DEFAULT_CONNECTION_URL, NODE_OPTIONS?

推荐答案

  1. websocket 服务器由 sockjs 处理,因此只要您使用标准的 wss,它就应该正常工作"(参见 https://github.com/sockjs/sockjs-node).如果您的客户端上的 websocket 实现是为使用 websockets 而构建的,那应该没问题.大气/陨石项目使用带有安全套接字的 node-ddp 客户端(有几个问题,但我认为它们已排序).(反过来,这取决于 faye-websockets 库)

  1. The websocket server is handled by sockjs, so as long as you use a standard wss it should 'just work' (see https://github.com/sockjs/sockjs-node). If you're websocket implementation on your client is built to use websockets it should be ok. The atmosphere/meteorite projects use the node-ddp client with secure sockets (there were a couple of issues but I think theyre sorted). (In turn which depends on the faye-websockets library)

我不太确定您使用哪种语言编写应用程序 B,但是您需要使用 DDP 客户端连接到您的服务器,或者您可以编写一个,DDP 规范相当open 和 可逆.有几个 DDP 实现,有些可能需要更新到 pre-1 版本规范:

I'm not too sure which language you're coding your app B in, but you need to use a DDP client to connect to your server, or you could write one, the DDP spec is fairly open and reversible. There are a couple of DDP implementations out there, some might need to be brought up to date to the pre-1 release spec:

  • Java (https://github.com/kutrumbo/java-ddp-client)
  • Ruby (https://github.com/tmeasday/ruby-ddp-client)
  • NodeJS (https://github.com/oortcloud/node-ddp-client) - Up to date
  • Objective-C (https://github.com/boundsj/ObjectiveDDP)
  • .NET (C#/VB.NET) (https://github.com/sonyarouje/DDPClient.NET)

此外,您可能会遇到麻烦,因为您发现与 new WebSocket("ws://" + host + ".meteor.com/websocket") 的连接没有结果,这是因为流星部署托管使用 ddp 代理(通过 ddp--xxxx-{my host name}.meteor.com 访问,但 xxxx 在您创建时也总是更改一个新的部署,你必须访问 html 文件并解析出 ddp 服务器是什么,或者在每次部署应用程序时记下它.

Additionally you might run into trouble, as you discovered a connection to new WebSocket("ws://" + host + ".meteor.com/websocket") is fruitless, this is because meteor deploy hosting uses a ddp proxy (which is accessed via ddp--xxxx-{my host name}.meteor.com, but the xxxx also always changes when you make a new deployment, you have to access the html file and parse out what the ddp server is or make a note of it every time you deploy your app.

如果您在端口 443 上连接,它应该是 wss.我不太确定 websockets 是否会重定向.这是服务器端的事情,所以如果您使用流星部署,您将无法控制它(也许当他们发布星系时,这可能会改变).也许 force-ssl 包可能会有所帮助?不过,不太确定它是否也强制执行连接的 websockets 部分.

If you connect on port 443 it should be wss. I'm not too sure websockets do redirects. This is a server side thing, so if you're using meteor deploy you wont have control over this yet (perhaps when they release galaxy this might change). Perhaps the force-ssl package might help? Not too sure if it also enforces the websockets part of the connection too, though.

对于 DDP,您无法在设置中指定任何已知设置

For DDP there aren't any known settings you can specify in the settings

对于流星部署托管,您不能更改 DDP 服务器以使用另一个服务器或更改环境变量(请参阅 https://github.com/oortcloud/unofficial-meteor-faq).

For meteor deploy hosting you can't alter the DDP server to use another one or alter the environmental variables (see https://github.com/oortcloud/unofficial-meteor-faq).

请记住,meteor 部署托管非常年轻&制造流星的人还没有发布他们的星系解决方案,所以这一切在未来可能会改变.

Keep in mind meteor deploy hosting is very young & the guys who make meteor still haven't released their galaxy solution so this might all change in the future.

顺便说一句,关于布局/间距,我不明白这个降价的事情.

Btw sorry about the layout/spacing, I can't get the hang of this markdown thing.

这篇关于如何通过 DDP (WebSocket) 协议访问meteor.com 上托管的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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