简体   繁体   English

带有 Java ECONNREFUSED 的 Heroku Websockets(连接被拒绝)

[英]Heroku Websockets with Java ECONNREFUSED (Connection refused)

I am writing a small game server using Java.我正在使用 Java 编写一个小型游戏服务器。

I use TooTallNate-Java-Websockets library to create my websocket server.我使用TooTallNate-Java-Websockets库来创建我的 websocket 服务器。 Everything works when I run my server on localhost , I can connect to it from everywhere.However when I submit my app to Heroku , every time I try to establish a socket connection I get an error ECONNREFUSED (Connection refused) .当我在 localhost 上运行我的服务器时,一切正常,我可以从任何地方连接到它。但是,当我将我的应用程序提交给 Heroku 时,每次尝试建立套接字连接时,我都会收到错误ECONNREFUSED (Connection denied)

Worth to mention , that when I am running my app with foreman which is supposed to emulate heroku environment , everything works as it should.值得一提的是,当我与应该模拟 heroku 环境的工头一起运行我的应用程序时,一切正常。

As a port for my websocket server I tried to use 8080 and many others in range between 5000 to 8000 .作为我的 websocket 服务器的端口,我尝试使用8080以及50008000之间的许多其他端口。

I can only guess what is going on there on heroku , as logs contain only basic info of http requests.我只能猜测 heroku 上发生了什么,因为日志只包含 http 请求的基本信息。

Please help , I am close to give up :(请帮忙,我快要放弃了:(

EDIT编辑

Here is what I have in my Proc file:这是我的 Proc 文件中的内容:

web: ./build/install/my-app/bin/my-app

UPDATE Created a simple abstraction app to showcase the problem: (Tested in foreman of course , and it works in local environment)更新创建了一个简单的抽象应用程序来展示问题:(当然在领班中测试过,它在本地环境中工作)

  1. My html/js tester : Testerpage我的 html/js 测试员: Testerpage
  2. My Main java Jetty server : Java Main我的主要 Java Jetty 服务器: Java Main
  3. Console error message : WebSocket connection to 'wss://test-websocket-yan.herokuapp.com:39773/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED控制台错误消息: WebSocket connection to 'wss://test-websocket-yan.herokuapp.com:39773/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I am answering my own question to share how I've managed to connect to Java websocket server on Heroku.我正在回答我自己的问题,以分享我如何设法连接到 Heroku 上的 Java websocket 服务器。

  1. Create your web socket server using Java , the implementation is up to you , you can use javax or Jetty websockets or TooTallNate-Java-Websockets , I've used Jetty.使用 Java 创建您的网络套接字服务器,实现取决于您,您可以使用 javax 或 Jetty websockets 或TooTallNate-Java-Websockets ,我使用过 Jetty。 Here is my implementation .这是我的实现 I have followed this example.我遵循了这个例子。
  2. When connecting to your web socket on heroku use the following scheme ws:// + yourHerokuAppAdress + yourSocketEndpoint .当连接到 heroku 上的网络套接字时,请使用以下方案ws:// + yourHerokuAppAdress + yourSocketEndpoint The endpoint is the relative adress that your websocket is listening on , in my case it is "/socket" .端点是您的 websocket 正在侦听的相对地址,在我的情况下它是"/socket" No Need to specify port !无需指定端口!

You must use the port that Heroku sets as the $PORT env var:您必须使用 Heroku 设置为$PORT env var 的$PORT

On Heroku, apps are completely self-contained and do not rely on runtime injection of a webserver into the execution environment to create a web-facing service.在 Heroku 上,应用程序是完全独立的,不依赖于将网络服务器运行时注入到执行环境中来创建面向网络的服务。 Each web process simply binds to a port, and listens for requests coming in on that port.每个 Web 进程只绑定到一个端口,并侦听来自该端口的请求。 The port to bind to is assigned by Heroku as the PORT environment variable.要绑定的端口由 Heroku 分配为 PORT 环境变量。

For more see: https://devcenter.heroku.com/articles/runtime-principles#web-servers更多信息请参见: https : //devcenter.heroku.com/articles/runtime-principles#web-servers

You might just need to have REDIS_URL set.您可能只需要设置REDIS_URL It was in REDISCLOUD_URL in my case.就我而言,它在REDISCLOUD_URL中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android ECONNREFUSED(拒绝连接) - Android ECONNREFUSED (Connection refused) IOException java.net.ConnectException:无法连接到/127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) - IOException java.net.ConnectException: failed to connect to /127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) java.net.ConnectException:无法连接到/192.168.10.110连接失败:ECONNREFUSED(连接被拒绝 - java.net.ConnectException: failed to connect to /192.168.10.110 connect failed: ECONNREFUSED (Connection refused java.net.ConnectException:无法连接到 /192.168.253.3(端口 2468):连接失败:ECONNREFUSED(连接被拒绝) - java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused) java.net.ConnectException:无法连接到 localhost/127.0.0.1(端口 80):连接失败:ECONNREFUSED(连接被拒绝) - java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused) CloudAMQP连接仅在Heroku上被拒绝 - CloudAMQP Connection Refused Only On Heroku Android WiFi Direct-客户端/服务器-ECONNREFUSED(拒绝连接)更新 - Android WiFi Direct - client/server - ECONNREFUSED (Connection refused) UPDATE Java SSL连接被拒绝 - Java SSL connection refused Java RMI:连接被拒绝 - Java RMI : connection refused Java RMI 连接被拒绝 - Java RMI Connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM