How can I access my localhost from my Android device?

前端 未结 30 2317
面向向阳花
面向向阳花 2020-11-21 05:53

I\'m able to access my laptop web server using the Android emulator, I\'m using 10.0.2.2:portno works well.

But when I connect my real Android phone, th

30条回答
  •  不思量自难忘°
    2020-11-21 06:21

    USB doesn't provide network to mobile device.

    If both your desktop and phone are connected to the same WiFi (or any other local network), then use your desktop IP address assigned by the router (not localhost and not 127.0.0.1).

    To find out the IP address of your desktop:

    • type into the command line ipconfig (Windows) or ifconfig (Unix)
      • on Linux the one-liner ifconfig | grep "inet " | grep -v 127.0.0.1 will yield only the important stuff
      • there's a bunch of suggestions on how to have a similar output on Windows
    • there's going to be a bunch of IP's
    • try all of them (except the forementioned localhost and 127.0.0.1)

    If your phone is connected to the mobile network, then things are going to be harder.

    Either go hardcore:

    • first find out your router external IP address (https://www.google.de/search?q=myip)
    • then, on the router, forward some port to :
    • finally use the external IP address and forwarded port

    Otherwise use something like xip.io or ngrok.

    NOTE: The ifconfig command has been deprecated and thus missing by default on Debian Linux, starting from Debian stretch. The new and recommended alternative for examining a network configuration on Debian Linux is ip command. For example to use ip command to display a network configuration run the following:

    ip address
    

    The above ip command can be abbreviated to:

    ip a
    

    If you still prefer to use ifconfig as part of your daily sys admin routine, you can easily install it as part of the net-tools package.

    apt-get install net-tools
    

    Reference is here

提交回复
热议问题