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.

Ido Ran
  • 10,584
  • 17
  • 80
  • 143
  • possible duplicate of [Is it possible to enable tcp, http and websocket all using the same port?](http://stackoverflow.com/questions/13791050/is-it-possible-to-enable-tcp-http-and-websocket-all-using-the-same-port) – Yuval Adam Sep 24 '14 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. – Ido Ran Sep 24 '14 at 13:56
  • Then why not just have two separate applications? One doing static web stuff, and one handling websockets? – Yuval Adam Sep 25 '14 at 14:06
  • because I need to rely the messages between the two - creating another application will not solve the problem. – Ido Ran Sep 26 '14 at 06: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. – Yuval Adam Sep 26 '14 at 09:05

2 Answers2

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.

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.

Ido Ran
  • 10,584
  • 17
  • 80
  • 143