how to connect to a server running on computer using computer's IP address? - node.js

I am working on IOT project in which I have to change some variables(fans speed, lights, etc). So just as a starter, I created a node.js server and tried to send requests to the server through a local network using local IP as
http://localhost:7000/users=mandar?lights=OFF
or
http://192.168.43.248:7000/users=mandar?lights=OFF
and it works fine.
Now I want to do the same over the internet. So I got Computer's IP address from https://www.google.co.in/search?q=myip and tried to send a request to the following URL:
http://(IP_address):7000/users=mandar?lights=OFF
This time it keeps on loading and finally shows this site can't be loaded.
So what is the right way to connect to the server through the internet?
Thank you.

You have to do port forwarding.
The IP address you get from the google search is the out-facing IP address of your router. However, your router knows your computer by your local IP address (i.e. 192.168.x.y).
You have to configure your router to send packets coming from internet destined to port 7000(or any other port) to your computer's port 7000.
Check your router's documentation on port forwarding. Likely there is a settings page on the web interface of your router that you can do the desired port forwarding. After configuring the router, there are several tools online to test if the port forwarding is actually working. I suggest you use one of those tools to verify the configuration before testing with your project.
You also might want to check if your router has a firewall. You can add an exception to the firewall such that a specific port number is reachable from the internet.

Related

Can't establish a connection NodeJS

I am a novice at networking, I have a NodeJS server running with server.listen(3000, '10.0.0.7'); and have forwarded port 3000 with the internal IP address of my server being 10.0.0.7. I can connect from another machine on my network by putting in the browser: 10.0.0.7:3000. It is my understanding that my external IP address should connect me to the router which should then forward me to the server I have set up on 3000.
Am I missing something important? Because I am unable to connect via the external IP address.
Also please note that my firewall is disabled.
I am neither a network expert so excuse me if I use any incorrect terms. In my understanding, you are right about the current configuration, however you are missing the last step. By default, your router makes your LAN unreachable from a so called “external ip”. Just for the definition: external ip in this case is every ip that is not in your LAN. Imagine if your router would allow any communication without you explicitly giving permission. Every open port on your LAN would be available for the network that your router connects to. That is definitely not desirable.
Lets look at it with an example, quoted from this article:
your router has an ip of: 5.6.7.8 if you access it from outer network (internet)
your router has an ip of: 192.168.1.1 if you access it from your LAN
your laptop is in your LAN and has an ip address of 192.168.1.10 and you want to expose port 3000 from your laptop to the outer network (internet)
You have 2 options:
You can expose the port via the configuration of the router (e.g.: you map 5.6.7.8:3000 to 192.168.1.10:3000 in the router configuration and now it will be accessible from the outer network on 5.6.7.8:3000. Note that you can choose any free port, ports don’t have to match.). Of course it is only possible if you have the option to configure the router and you are willing to do so. (e.g.: if you are not in a café)
You can use some tunneling tools like Ngrok or OpenSSH, which make a direct tunnel between the external machine and your server. This can also work if you don’t have the ability to change the router configuration.
Hope I was able to help. Good luck.

How to expose tornado websocket from local machine

I have built a d3.js dashboard that ties into a tornado websocket. Everything works perfectly locally. I now would like to have the ability to share the websocket with a few friends, nothing production. Is there a way to do this without a big deployment on Heroku or other similar service? I've googled and can't seem to find an answer. Thanks
Not specific to Tornado. This is more of a networking question.
What you want to do is:
Run your server on your computer.
Connect to the internet.
Note down your public IP address.
Give your IP address to your friends.
Certain things you need to take care of:
Run your server on a higher, non-standard port (e.g. 8000 would be good) because ISPs block traffic to port 80 and other standard ports.
The IP address assigned to you by your ISP will most probably be dynamic. That mean, every time you diconnect and reconnect to the internet, your IP address will change.
Turn off your computer's firewall to let in the traffic at whichever port your server is running.
Finally, you'll need to configure port forwarding on your router. What that means is all the incoming HTTP requests will arrive at your router at your public IP address. But your computer where you'll be running your server will have an internal IP address assigned by your router. So, you'll need to forward incoming requests to your computer's internal IP.

Node.js & express how to open my rest api on localhost to remote partners?

My partners can send http requests to my domain, like this:
https://www.example.com/getrequest/
As my domain is public.
And I have also enabled CORS.
How to enable such a thing with my localhost during development?
I have tried to visit my Node.js server with my IP address in the url bar in the browser of a different device like this:
http://myip:8080
But it asks for the WiFi password.
How make my IP available for incoming requests, just similar to my VPS so it will be available to development with partners?
Thanks.
In order for your computer to be accessible from the internet you have to enable port forwarding for your router
Port Forwarding
The thing is that your router has a unique IP address yet many devices connect to it so they all share the same IP. The router with port forwarding links a specific device to a specific port so that you can access your computer from http://ROUTERIPADDRESS:DEVICEPORT from the outside world.

how to view my website from anywhere which is running in my laptop at home.?

Things I did so far.
my website is running on port 80.
had opened my port 80 with the help of VPN book. confirmed with canyouseeme.org.
Created an account in noip.com. Created a hostname.
using the AsusZenfone3 mobile phone and airtel 4g mobile data. getting internet to my laptop via Hotspot/Tethering using wifi from phone and laptop.
had downloaded DUC from noip and it is running fine.
had configured a device in noip.com for my host like below,
- hostname
router brand as Asus(I don't use any router/ I don't know what router is used)
-software/device as HTTP
Is there any computer running on your network? Yes
downloaded Duc
port 80 check success
my host has been successfully configured.
I also added rules to my firewall to enable TCP and UDP 80 port access.
But still, I am not able to access my website.
I tried calling my website from the proxy server, I get an empty result from the server.
Cannot say for certain, but it sounds like you opened port 80 on your router but likely did not forward that port to an address on your local LAN.
Somewhere in your router config you should be able to find a port forward option. So any traffic received on that port would need to be forwarded to the local IP of the computer running the webserver.
Problem
Your port is not forwarded through your gateway connection.
Solution
Fwd Port Forwarding app for Android phone

NodeJS works only on my network

I have my nodejs server app running on my windows 10 machine which uses my home internet connection.
When I am connected with my phone to my home internet and write the IPv4 Address and port I get a response and my web page loads, but when I use a different internet connection it doesn't load.
I turned off the firewall, tried a lot of different ports but nothing worked.
I tried app.listen(8000) or app.listen(8000, "0.0.0.0") but both didnt fix the problem.
Any ideas what might be the problem?
OK I found out how to do this, my port forwarding was not configured correctly.
Here is how I solved it in case someone has the same problem:
Connected to my router (in cmd write ipconfig, copy the Default Gateway ip and paste in browser).
Clicked port forwarding (each router have it in different place), set external IP to 0.0.0.0 and my app port, and set internal ip to my computer ip (you can just write "what is my ip" in google) and same app port.
I hope it will help someone.

Resources