Ido Ran
Ido Ran

Reputation: 11374

NodeJS app on Heroku with both TCP Socket and WebSocket

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.

Upvotes: 0

Views: 406

Answers (2)

Ido Ran
Ido Ran

Reputation: 11374

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.

Upvotes: 0

Jacob Vorreuter
Jacob Vorreuter

Reputation: 11

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.

Upvotes: 1

Related Questions