how to find process.env.PORT port number in heroku? - rest

I need to post json data from a IOT device to the server api endpoint. But it requires the port number. How can i find a port number for process.env.PORT in heroku?

You don't need to know that port number.
Within the process, Heroku requires you to bind that process. But their router will expose ports 80 and 443 and route requests properly to the process(es) running your app.
In order words: you bind to $PORT in a single process. Heroku's router binds to 80 and 443, and routes to one of many processes (or dynos).
All you have to do is make a request to your-app-name.herokuapp.com.

Related

Issue getting my web server to work from external devices

I am attempting to set up an apache2 web server on my raspberry pi. I am able to connect to it by doing http://localhost:8080 (8080 because my router blocks port 80). Although when I do http://my.pub.lic.ip:8080 the connection times out. I set up port forwarding so that requests going to my router on port 8080 go to my raspberry pi on port 8080. This does not seem to work but I'm also not sure if the port forwarding is the cause or if it is something else. Any suggestions?
Is your web server configured to listen on the network interface besides localhost?
https://httpd.apache.org/docs/2.4/bind.html
For example, to make the server accept connections on both port 80 and port 8000, on all interfaces, use:
Listen 80
Listen 8000
To make the server accept connections on port 80 for one interface, and port 8000 on another, use
Listen 192.0.2.1:80
Listen 192.0.2.5:8000
You can try using nmap by finding your router's public IP and on the raspberry pi type nmap my.pub.lic.ip This will show you what services are actually being published to the world. This gives more insight to the problem.
I got the web server up and running although for some reason it appears that my isp would only allow it to be hosted securely (as an https page)(I'm not sure if that's the right way to phrase it). To achieve this for free, I used cloudflare's ssl service. A tutorial to set it up for apache2 can be found here

Dataplicity unable to access port

I am having a problem in accessing ports with my Pi. I am using dataplicity to access it online.
I can access my page with this URL.
https://my_id.dataplicity.io
Can't access when I use this
https://my_id.dataplicity.io:9090/
But I can access it in my local.
http://localhost:9090/
What could possibly be the problem here?
Thanks!
At the present time wormhole forwards HTTP traffic to port 80 on your device but forwarding to other ports is not something that can be achieved by default.
The port forwarding feature is coming as part of our PRO pricing plan in future.
As an interim workaround, it is possible to redirect port 80 on your Pi to another local port on your Pi using a reverse proxy (for example using nginx). Although wormhole itself will still communicate with port 80 on your device, nginx could listen on port 80 and forward this to another local port of your choosing. Here's a nice article that could get you started:
https://www.keycdn.com/support/nginx-reverse-proxy/

which port is being used by a local web server?

We are using an internal server to host our staging website. I was trying to use browserstack to do compatibility testing on the virtual environment that they provide. In order to setup the virtual environment, I need to specify the port which is being used by the local web server. How can I find out which port is being used by our server? Do I need to go check the settings from the IIS in the server machine?
Web server can run on any port. But the default port is 80. When you type in the URL of a web site the browser uses the default port 80 and connects to it. There are lot of occasions when other ports are used, mostly when more than one web server is needed in the same machine. Like webmin uses port 10000 by default.
For any web server not using port 80 you have to specify the port also with your url like http://yoursite.com:port in case of default webmin install it is like http://localhost:10000
Note:HTTP uses 80 and HTTPS uses 443 by default.
This is documented in their tab for local testing.
Basically you do not need to provide 80 as a port, because it will be used by default.
If the port number is not provided, a default port number of 80 is
used. If the port number is present in the URL, it will be extracted
automatically. To test servers with SSL, check the HTTPS box. Once the
option is checked, you can enter a SSL port number that is independent
of the HTTP port number. When the connection is established, the HTTP
and HTTPS connections appear as separate links.

multiple sockets sharing a port in node.js (via socket.io)

I am not sure how to use a single port at server side simultaneously for multiple sockets. How can we do it in node.js. I am currently using socket.io and have one socket per port. In case solutions do not exist but is possible then also please give your suggestion to achieve the same. Also what issues can be there if we share a port? What could be other related options considering the situation that clients can be idle but will consume a port on server as we need to maintain a socket connection for each client?
Assuming your server is running on port 80, here is what happens underneath:
Server listens port 80.
Client1 connects to server port 80 from its port 12345
Server accepts client1's connection request and assigns port 9876 to commune with client1.
Server continues listening port 80.
So despite what you think, the port 80 is not consumed, it is a listener. Your computer probably has 50000 ports at free, so there is no problem.
FYI: Ports cannot be shared among other processes. Only Node's child processes can be shared, have a look at how it can be: http://nodejs.org/docs/latest/api/cluster.html

Using port 80 for non http

Is it possible to use port 80 for non http traffic ? For example I'm making a small script that will communicate with a friends computer through the internet, however they must port forward it to get past the router. Is there a problem with using port 80 in the script so it will be let through automatically ? Is there some part of this i don't understand that will not let non http data through ? Please explain :)
there is no problem doing that. in fact, skype's default behaviour is to use port 80 and port 443 to transport voice!
There are a lot of ISPs that actually block port 80, so you might want to try a different port if you are having a problem (still needs to be forwarded)
The firewall on the computer also needs to be set to allow the incoming traffic.
This will work fine, but your friend may still need to setup port forwarding
If your friend's PC is the one listening on Port 80, he will need to setup port forwarding. Otherwise, how would the router/NAT know which computer in the house to bridge the connection to?
But if your friend's PC is the one making the outbound connection, then likely no port forwarding is needed at all on his end.
In other words, port forwarding (for TCP) is only for inbound connections. The router/NAT will automatically setup a port mapping scheme for outbound connections (as it does it with all web traffic).