live server vscode on another computer - visual-studio-code

I have 2 computers. when I open the project with live server on the first one it gives me this url 127.0.0.1:5500/index.html
I want to put that url on the other computer's browser but it doesn't work.
is there any solution to this?

This is what worked for me in VS Code:
1.- Go to your extensions option:
2.- Make sure you have the "Use Local Ip" option checked:
3.- Check on your terminal for your local Ip address (ipconfig on windows for example) and substitute the ip address from your live server url with you local ip:

You can try port forwarding using powershell on the hosting computer. I use wsl2 and when I want a preview on another computer I port forward using powershell
netsh interface portproxy add v4tov4 listenport=xxxx listenaddress=(host pc ip address) connectport=yyyy connectaddress=(wsl2 ip address)
In your case try making the listenaddress and connectaddress the same (which is your main pc) and the listen and connect ports 5500 using the above script.
After that the last step you should perform is add Inbound Rules inside your firewall.

you can go to settings live server and check the use local ip option, then you stop live server and start over again.
Now live server use an direction with local ip and you can open your file in other pc.
enter image description here

It doesn't work because you are using loopback address (127.0.0.1), in order to access your live server on entire LAN you need to change this address in vscode/liveserver settings to your private address, it will be something like (192.168.100.XXX)

put port 5500 in firewall to access from other pc
connect pc via lan and set static ip
then call it like xxx.xxx.xxx.xxx:5500/

You need nothing extra.
Just type your local IPv4 Address which you can find in Command Prompt by typing " ipconfig ", then on another computer in browser type this IPv4:5500 and it's done.
(You must have Live Server On)
Example: 192.168.1.5:5500

Related

Live Server: This page isn’t working 127.0.0.1

I got the message when I use live server at VS code.
This page isn’t working 127.0.0.1
I checked use local up option. but it still doesn't working.
I tried changing live server : host ip address to my ip address. But it still doesn't working.
what can I do?
*use local ip as host option picture:
https://i.stack.imgur.com/COq2I.png
In your given image, you have checked the option that hosts the liveserver on your IP, so you should have a look at yourip:port.
For example, if you is 10.43.156.141, and post is 5500 then
the server will be on http://10.43.156.141:5500
EDIT
To get your IP
If you are using Windows, use:
C:\User>ipconfig
If you have Linux, use:
$ ifconfig
Or just visit https://api.ipify.org/ to get your IP.
Note: When you visit https://api.ipify.org/ disable your VPN or Brave Shield or any Privacy Booster if you have
Edit:
The port is shown here
Edit the port in the live server
If you dont know the port, just add the below code in vscode's settings.json
"liveServer.settings.port": 5500
Change the 5500 to the port you want. Mostly 5500 is used.
Try using IPv4 Address.
Fo example if your IPv4 Address is 172.31.96.1 and your file name is index.html, Then change the URL in the browser from http://127.0.0.1:5500/index.html to http://172.31.96.1:5500/index.html

Why can't I enter the url on my phone's browser to view my live site?

I use an extension called Live Server in Visual Studio Code. When I run live, the browser opens and the url is http://127.0.0.1:5500/index.html. Why can't I open this url on my phone's browser to see the live site on the phone. Is there a way to do this (Live reload on phone and browser)?
Note: I also develop using ionic and when I ionic serve I can see it on browser and when I open the ionic dev app (not ionic view!), I can see the live app on the phone. I can view it on multiple devices with the condition of all devices being in the same network which I am fine with.
127.0.0.1 is a special-purpose IPv4 address reserved for loopback purposes. That is, this IP refers to your computer itself.
By entering http://127.0.0.1:5500/index.html in your browser, you're requesting web page within your computer.
In normal case, your computer will be in a NAT network (under same wi-fi AP for instance), and you'll be assigned with a virtual IP. Normally it's 192.168.x.x.
You may enter the following command in your command prompt to see your IP address.
ipconfig
If you're using Mac or Linux, use this instead.
ifconfig
As a result, under your network interface card, you'll get your IP Address.
If the IP address belongs to virtual IP, then you may access it with your phone using
http://< Your IP Address >:5500/index.html
If it's not virtual IP, it is Public IP. Then, you'll have to configure appropriate Firewall settings under this circumstance.
Hope this will help.
You cannot open the same url on your phone, because that url host (127.0.0.1) refers to the localhost (the same machine).
If your phone and server are on the same network, you can replace the current host with the servers local IP.
So if your servers local IP is: 192.168.0.36
the URL you enter in your phone should be http://192.168.0.36:5500/index.html.
I had a same problem.
Solution: Control Panel -> Windows Defender Firewall -> Allow an app or feature through Windows Defender Firewall -> Allowed "code.exe" app.
Run ipconfig and find your private IP.
Make sure your phone is on the same network.
go to http://192.168.0.***:5500/
Open Live server's settings.json and add these two settings "liveServer.settings.useLocalIp": true and "liveServer.settings.host": "localhost". Then type your localhost ip in your mobile browser (in my case it was 192.168.0.110) with the rest of the Live server URL i.e. 192.168.0.110:5500/index.html. This worked for me.
Let me clear this out for you. we call localhost or 127.0.0.1 as loop backs. which will itself point to the same machine(means that particular service should also be hosted in the same machine). what Microsoft did with visual studio live share is that if have the live share extension it will create a reverse proxy between the host(where the server is hosted) and the target (In this case your browser) which means even though your host is in a different country the extension will tunnel the transparent proxy to your loop-back address. visual studio live share extension is what you phone doesn't have and Microsoft doesn't support yet. If you still want to access your local service what you can do is turn off the firewall(or pass through that particular port where ur service is hosted) and connect your phone to the same network as your machine with the service running and instead using http://127.0.0.1:5500/index.html use http:// UR SERVER IP :5500/index.html you can get UR SERVER IP by giving ipconfig in windows command prompt or ifconfig if ur server is on linux.

Server Connection with public IP

I have setup a simple HTTP java server running locally on port 8000. It simply prints a message "Hello world" when a request comes. When I try to ping it from the browser by running http://localhost:8000/test I get my message printed.
I want to get the same results from another computer that is not local. When I try to use my public IP lets say http:/43.xxx.xxx.xxx:8000/test (even from the same machine) I get an ERR_CONNECTION_REFUSED .
I probably suspect that has something to do with the firewall. Can anyone guide me a little more because I lack the experience?
Thanks in advance
You don't specify what host OS your server/firewall is running so I'll keep this generic...
Without knowing your application, it seems like the server is sending a reset (RST packet) when the first SYN packet shows up indicating that the port (on that interface [your external]) is closed. You can do a quick port scan from here (https://mxtoolbox.com/PortScan.aspx) if you don't have access to a remote machine to test with. Odds are, TCP/8000 will not be open.
If it is, in fact, closed, you'll have to look at the firewall that your host OS is running and find out how to allow TCP/8000 to your host. In a major firewall vendor, your rule would look similar to this:
Source: Any
Destination: Your Public IP Address
Service: TCP/8000
Action: Allow
Logging: Full
That being said, you mentioned this was a PC so look into "iptables" (if you're running *nix) or the Windows Firewall (if you're running Windows) on adding firewall rules (Unfortunately I just joined and can't ask questions/comments, yet).
If you really want to find out what packet is being sent, run a tcpdump on your external interface (let's say eth1) (assuming your remote IP is 1.2.3.4 and your home public IP is 4.5.6.7):
tcpdump -nn -vvv -e -s 0 -X -c 100 -i eth1 host 1.2.3.4 and host
4.5.6.7 and port 8000
Here you're looking for the SYN/SYN-ACK/ACK for a successful TCP negotiation or SYN/RST if there is a firewall rejecting (not dropping) the TCP stream to the port.
Once the port is open on the host OS firewall, take a look at the application to make sure it's configured properly. If this were a standard webserver, you could take a look at the configuration files for the "Allow from" directives to make sure that everyone can access the site. If this is a custom application that you've created, you'll have to check this yourself.
I finally solved my problem. I needed to open a forwarding port in my router that maps my local ip address to the public. My router is TP Link so this what I did:
http://www.tp-link.com/us/faq-72.html
Also in order for this to work every time and not to have to reconfigure this every time I reconected to the router (because I get a new local IP), I have created a static local ip for my server following this guide:
http://www.tp-link.com/us/faq-182.html
Thanks for all the replies.

SSH from public IP to non-public IP after connection established vice versa

I have a "mini computer" that uses 3G/4G modem for networking. My ISP doesn't assign public IP for it so there's no way to make an SSH connection directly to it.
I only need it to have the SSH-connection with my home computer. For my home computer I can have a public IP (or rather do some port forwarding from my router) and I also can use dynamic DNS service with it.
So.. If I would set my "mini computer" to connect my home computer every now and then (which it can thanks to dynamic DNS), would it be somehow possible to SSH back to the device since there obviously already is a valid socket/route between them?
Home computer's OS is Win10 and other one's is somewhat modified Raspbian.
You can use SSH to create a tunnel back to your system, i.e.
ssh -R2222:127.0.0.1:22 remote-host
will connect to remote-host per SSH and opens a tunnel on this host port 2222 back to your local system where it then ends in 127.0.0.1:22, i.e. your SSH server.

Open the localhost website from a server pc

This might be an easy question, but I am not familiar with these stuff.
Basically I have a server pc that I connect through my pc, and there is this webpage http://localhost:8080/. I can only access this address when I log in my server pc. Now I wanted to know how I can access this webpage in my pc (without having to remotely connect to my server pc). Any help will be appreciated.
you can access to your website (if your web server accept external requests) by type this code to your browser address bar from your pc:
<server ip>:8080
replace
<server ip>
with your server ip like this:
192.168.1.10:8080
Okay, so quick networking 101, localhost is a hostname that maps to the IP address of of 127.0.0.1 and these point to the local machine, i.e. your server.
In order to access that page within the same network, you'll need an external IP address. So say you're in the network of 192.168.1.0/24 and the server is on IP address 192.168.1.100. So in order to access your stuff from another machine, simply replace localhost with that IP and it should work. If not, you've got firewall issues, and those are another topic.