So, to answer your questions:
You cannot have a single application that runs on multiple ports on a single Heroku dyno.
You CAN, however, have multiple Heroku dynos running, and each one running different commands. This allows you to run different 'types' of servers on Heroku within the same project. The way you do this is by specifying how to run your different types of servers in your Procfile
, for instance:
web: node server.js
other-web: node other-server.js
To run one instance of server.js
, and one instance of other-server.js
, you could simply tell Heroku to run those processes as dynos, like so:
$ heroku ps:scale web=1 other-web=1
Now -- in regards to websockets, Heroku supports them natively, as of a couple years ago (you can read more about this here: https://devcenter.heroku.com/articles/websockets). This means you can use native websocket applications on Heroku by following typical websocket patterns.
In the documentation I just linked you to, there's an example Node app -- it also outlines how it works, specifically.
Finally -- regarding subdomains -- the other Stack Overflow post you linked to is no longer accurate. Heroku added support for wildcard domains (usually for multi-tenancy purposes) a long time ago.
This means that if you're building an application where you want to dynamically serve pages to a user based on subdomains: you're in luck! This is fully supported. You can do it by saying:
$ heroku domains:add *.example.com
When you update your DNS to point to the wildcard, you should start seeing all subdomain requests come into your Heroku app.
To learn more about the Heroku + subdomain stuff, they have an excellent article about it here: https://devcenter.heroku.com/articles/custom-domains#add-a-wildcard-domain