获取客户端上流服务器的端口号[在heroku上运行]

获取客户端上流服务器的端口号[在heroku上运行]

问题描述:

我正在尝试将我的dart应用程序部署在heroku上,但是即使当我的流服务器在dyno中运行时,我也不知道如何获取客户端代码上的端口号以进行连接通过websocket服务器。由于我无法使用 Platform.environment ['PORT'] ,因此我不知道如何获取端口。

I am trying to deploy my dart application on heroku but even when i have got my stream server running in the dyno, i don't have any idea as to how can i get the port number on client side code to connect to the server via websocket. Since i cannot use Platform.environment['PORT'], i don't know how to get the port.

我的客户端网络套接字地址是这样的:

My client side websocket address is this:

var port = '<The port number i need>';
var url = 'ws://0.0.0.0:$port/ws';

为成功部署到heroku付出了很多努力。请告诉我,有一种方法可以使这项工作。

It has taken a lot of effort to deploy successfully to heroku. Please tell me that there is a way to make this work.

请参阅Gunter 为什么我的应用程序无法在Heroku上建立websocket连接?碰巧是客户端不需要实际的端口进行连接。

Referring to the link given by Gunter Why won't my app establish websocket connection on Heroku?, it just happens to be that the client side doesn't require an actual port to connect.

做window.location.origin并用ws://替换http://可以解决问题!尽管问题在于即使我的​​数据库全部打开,使用对象查询数据库还是存在一些问题。

Doing the window.location.origin and replacing http:// with ws:// did the trick! Although problem is that even when my database opens up and all, there's some problem when using objectory to query upon it.