get port number of stream server on client side [running on heroku]

喜欢而已 提交于 2020-01-17 08:54:40

问题


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';

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


回答1:


I haven't used Heroku myself yet but here the doc says

The Heroku platform automatically routes HTTP requests sent to your app’s > hostname(s) to your web dynos. The entry point for all applications on >the Cedar stack is the herokuapp.com domain which offers a direct routing path to your web dynos.

It should be possible to make a HTTP request to the hostname of your web dyno to connect to your server and your server should be able to do the Platform.environment['PORT'] and report the result back.




回答2:


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.

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.




回答3:


You can try " heroku run bash " and run your server in terminal then you can easily find your port in which your app is running.



来源:https://stackoverflow.com/questions/29227534/get-port-number-of-stream-server-on-client-side-running-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!