且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过 DDP (WebSocket) 协议访问meteor.com 上托管的应用程序?

更新时间:2023-10-20 15:13:40

  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.