0

Is it possible to host NodeJS application on Heroku and accept both TCP Socket and WebSocket connections?

I need it to rely plain-old TCP Socket clients to web-front-end application?

Thank you, Ido.

5
  • possible duplicate of Is it possible to enable tcp, http and websocket all using the same port? Commented Sep 24, 2014 at 11:26
  • no, I don't need it to be in the same port - perfectly fine that each communication type will be in separate port. Commented Sep 24, 2014 at 13:56
  • Then why not just have two separate applications? One doing static web stuff, and one handling websockets? Commented Sep 25, 2014 at 14:06
  • because I need to rely the messages between the two - creating another application will not solve the problem. Commented Sep 26, 2014 at 6:29
  • The Right™ (and scalable) way to do this is is to separate the two environments, and have them pass messages between them using a message queue/broker. Moreover, Heroku will only give you on port per process, so you can't actually bind to two distinct ports from the same application/process. Commented Sep 26, 2014 at 9:05

2 Answers 2

1

Heroku apps bind to a port provided to them at runtime in the $PORT env var. That's the port that the Heroku router knows about and currently only a single port per dyno is supported.

The Heroku router supports arbitrary protocol upgrades: https://devcenter.heroku.com/articles/http-routing#protocol-upgrades

You could use that to upgrade to a WebSocket or TCP connection based on request headers or path.

Sign up to request clarification or add additional context in comments.

Comments

0

I used Ruppell's Sockets I was able to host both HTTP, WebSocket and TCP endpoints in the same app in Heroku.

I agree that in the long run separating the monolithic app to two or more applications may be the right way to go, but I'm pretty sure it is not the way to start and will just over-complicate things.

P.S. Ruppell's Sockets works for any language with sockets (which is about any language) not just NodeJS.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.