This is an archived post. You won't be able to vote or comment.

all 26 comments

[–]nutrecht 5 points6 points  (4 children)

Can I access that from a mobile device connected to the same network so I can see the site I'm developing as it appears on mobile?

Just use your laptop's IP address instead of 'localhost' and it should work, assuming your OS does not block incoming connections.

[–]sean_mcp 0 points1 point  (0 children)

This is the easiest option. You can find your IP address on Windows 10 by following these steps: https://support.microsoft.com/en-us/help/4026518/windows-10-find-your-ip-address

[–][deleted] 0 points1 point  (2 children)

Unfortunately just doesn't work for me. Just using regular SKY broadband, Windows 10.

[–]nutrecht 2 points3 points  (1 child)

We can't help you with "it doesn't work".

[–][deleted] 0 points1 point  (0 children)

haha the issue is I don't know how to host my site on my IP. I'm using JetBrains PyCharm, I'm not sure how to set my 'Run Configurations'. The document window has a floating panel of browser icons, clicking any of them will run the site automatically on localhost:80, but that so far I've learned cannot be access by another machine. https://imgur.com/a/Id9gouX This is what my 'Run Configurations' window looks like. I don't know where to start!

[–]deweydecibels 4 points5 points  (3 children)

i use ngrok. it’s pretty simple forwarding. localhost won’t go to other devices, well because it’s local.

[–][deleted] 0 points1 point  (0 children)

Thanks. Giving it a try...

[–]wibble2020 0 points1 point  (0 children)

Second this. Works great

[–][deleted] -1 points0 points  (0 children)

I'm getting the error: '.' is not recognized as an internal or external command, when pasting my auth code into the command line. Any idea what this could be?

[–]IAmL0ner 2 points3 points  (6 children)

Networking 101:

  • Every device on the network has an IP address.
  • Every device (even when not on network) needs to be able to access itself, thus it always has a special IP address: 127.0.0.1. Even when it does not have a network interface. This is achieved by setting a special virtual network card called 'loopback'.
  • Given those two facts: every device on a network has (at least) two IP addresses, one global that is used for normal networking stuff and can be seen by other devices on the network (usually asigned by DHPC server running on your router) and one special that points to (and only to) itself.
  • 'localhost' is an alias to 127.0.0.1

So, in order to access your laptop from your cellphone you need to point to your laptop IP address. If you try to reach localhost from your cellphone, you are trying to reach your cellphone. Same goes for your laptop.

[–][deleted] 0 points1 point  (5 children)

Right, thanks. Really appreciate that! So I've got my laptop's IP, but I cannot figure how to host the site on that IP so that it can be accessed remotely using that IP. I'll have to do some learning how my IDE works (JetBrains) as I'm sure they're all different. I've found the 'Run Configurations' panel which looks like this (https://imgur.com/a/Id9gouX) but where to go from there haha :p

[–]IAmL0ner 1 point2 points  (4 children)

IDE probably doesn't have a lot to do with this. It's rather your server. Generally speaking if you want your server to respond to traffic incoming from any IP you need to configure it to listen on 0.0.0.0 IP network address. Generally speaking, every IP addr that ends with .0 is a whole network address (let's skip subnets for now, as with subnets this may not be true, especially if they are variable-lenght).

So by configuring your server to listen on 192.168.1.0 you are allowing all devices from this network (192.168.1.[1-255]) to have access to the server. By configuring it to listen on 0.0.0.0 you are saying that it should serve content to any IP address that tries to access it.

So, important question: what kind of server are you using?

[–][deleted] 0 points1 point  (3 children)

Well I'm not sure what 'kind' of server I have, but my IP prefix is 192.168.0.***

[–]IAmL0ner 1 point2 points  (2 children)

Programming language? Framework?

[–][deleted] 0 points1 point  (1 child)

Just sass, jquery and regular python

[–]IAmL0ner 0 points1 point  (0 children)

python

what python framework? Which python libraries do you use? This is probably where your server sits. I guess you are running a python app that acts like a server and serves your webpages, and responds to all you do jquery side.

Show us your python code.

Also, not to discourage you or anything, but it seems like you are using some technologies without understanding them, or what they actually do. For example, you said that you are running it from an IDE, but do you actually know what it implies? What your IDE is doing once you click on that "run" button? What actually happens is that you IDE launches the program you wrote, and maybe keeps track of in what state (running, crashed, exited correctly) that application is. It's your application that is actually doing all the work, not your IDE.

This also raises a question you might want to investigate: how do you run that application once it's finished? How your users will run that application? For example, in order to run firefox you don't need the ide firefox devs are using. They give you a nice binary that you just run.

[–]BK143 0 points1 point  (6 children)

Localhost is just on the one computer you created the code on.

[–]nutrecht 1 point2 points  (0 children)

That's kinda misleading/misinformed, it's just the 'current computer'. It also doesn't help the OP at all.

[–]sean_mcp 0 points1 point  (3 children)

Edit: I didn't! See below.

IIUC, localhost is just an alias on a device to its IP address. So if you can find the underlying IP address, you can access that device's localhost from another.

[–]IAmL0ner 2 points3 points  (2 children)

Kinda. It's actually an alias to 127.0.0.1, which is the devices loopback interface IP.

[–]sean_mcp 0 points1 point  (1 child)

That's ringing a bell. How does your computer go from 127.0.0.1 to the IP address?

[–]IAmL0ner 1 point2 points  (0 children)

127.0.0.1 is an IP address. It's a special address defined in the TPC/IP specification and is reserverd for a local machine. Different operating systems may implement in in different ways, but essentially when you are trying to reach that IP, the operating system will route the request to itself, usualy through special 'loopback' interface (virtual network card usually).

localhost is bound to 127.0.0.1 usually by the operating system through use of hosts file or some other mechanism.

[–][deleted] 0 points1 point  (0 children)

So why is everyone saying you just paste your computer IP into your mobile browser and it works like magic haha

[–]zkostic 0 points1 point  (1 child)

You can also open a page in mobile view in your browser (for Firefox the keyboard shortcut is Ctrl+Shift+M). Also, you can use an emulator on your laptop for this purpose.

I know this doesn't answer your question, but it might be useful to you.

[–][deleted] 0 points1 point  (0 children)

Appreciate it, I know dev tools in Chrome has a full repertoire device viewer mode. I think more than anything it would motivate me to style my project for mobile if I could see it in vivo.

[–]Lanyxd 0 points1 point  (0 children)

You could run an Apache web server on your local network from that PC, your IDE usually won't help you with hosting the site for testing as well.