Heroku- Web进程在启动后90秒内无法绑定到$ PORT.TooTallNate Websockets

dya*_*ude 9 java heroku websocket

我正在使用一个tootallnate websockets服务器来监听来自网站的连接.

如何在heroku上建立与服务器的连接?

当我的网站尝试连接时

wss://Heroku-Name-39329.herokuapp.com/
Run Code Online (Sandbox Code Playgroud)

要么

wss://Heroku-Name-39329.herokuapp.com:5000/
Run Code Online (Sandbox Code Playgroud)

我的heroku记录输出.

at=error code=H10 desc="App crashed" method=GET path="/" host=wss://Heroku-Name-39329.herokuapp.com request_id=4afca002-2078-439c-85dc-ad6ef7db50d2 fwd="207.244.77.23" dyno= connect= service= status=503 bytes=
Run Code Online (Sandbox Code Playgroud)

然后(Still Heroku Logs)

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed
State changed from crashed to starting
Starting process with command `java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server
Run Code Online (Sandbox Code Playgroud)

我的javascript日志

WebSocket connection to 'wss://Heroku-Name-39329.herokuapp.com/:5000/' failed: Establishing a tunnel via proxy server failed.
Run Code Online (Sandbox Code Playgroud)

我在服务器中设置的应用程序是.

String host = "";
int port = 5000;
Run Code Online (Sandbox Code Playgroud)

我的Procfile

web: java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server
Run Code Online (Sandbox Code Playgroud)

cod*_*ger 12

试试这个:

String host = "0.0.0.0";
int port = System.getenv("PORT");
Run Code Online (Sandbox Code Playgroud)

在Heroku上,您必须绑定0.0.0.0并使用分配给您的应用程序的端口,该端口包含在$PORT环境变量中.

从客户端,您不需要指定端口,因此只wss://Heroku-Name-39329.herokuapp.com/应使用(而不是使用5000 的端口).


Mar*_*ton 11

Heroku希望你使用某个端口.

将其添加到Procfile以获取该端口:

-Dserver.port=$PORT
Run Code Online (Sandbox Code Playgroud)

所以你的看起来像这样:Procfile

web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes/:target/dependency
Run Code Online (Sandbox Code Playgroud)