DEV Community

Ashen Chathuranga
Ashen Chathuranga

Posted on

Accessing a Laptop's Server on Port 80 from Your Phone via Wireless Debugging

This guide explains how to access a server running on port 80 on your laptop from your phone using wireless debugging and Chrome DevTools.


Prerequisites

  1. ADB (Android Debug Bridge) installed on your laptop.
  2. Both your laptop and phone must be on the same Wi-Fi network.
  3. A server running on your laptop's port 80 (e.g., a local web server).

Step 1: Enable Wireless Debugging on Your Phone

  1. Enable Developer Options on your Android phone:

    • Go to Settings > About Phone.
    • Tap Build Number 7 times to unlock Developer Options.
  2. Navigate to Developer Options and enable Wireless Debugging.

  3. Pair your phone with your laptop:

    • Get your phone's IP address:
      • Go to Settings > Wi-Fi > Network Details.
      • Note the IP Address (e.g., 192.168.x.x).
    • Open a terminal on your laptop and execute:
     adb pair <PHONE_IP>:<PAIRING_PORT>
    

    Replace <PHONE_IP> with your phone's IP and <PAIRING_PORT> with the pairing port displayed in Developer Options. Follow the on-screen instructions to complete pairing.

  4. Connect to your phone:

   adb connect <PHONE_IP>:<ADB_PORT>
Enter fullscreen mode Exit fullscreen mode

Replace <ADB_PORT> with the debugging port (usually 5555).


Step 2: Port Forwarding Using ADB

To allow your phone to access the server running on your laptop:

  1. Forward Ports: Use the following ADB command to forward your phone's port (e.g., 8080) to your laptop's port 80:
   adb reverse tcp:8080 tcp:80
Enter fullscreen mode Exit fullscreen mode

This maps your phone’s port 8080 to your laptop’s port 80.

  1. Access the Server from Your Phone:
    • Open a browser on your phone.
    • Enter the URL: http://127.0.0.1:8080.
    • This redirects traffic from your phone’s port 8080 to the laptop’s port 80.

Step 3: Verify via Chrome DevTools

  1. Open Chrome on your laptop.
  2. Navigate to: chrome://inspect/#devices.
  3. Ensure your phone is listed under Remote Devices.
  4. Use the Port Forwarding option in DevTools if needed to manage ports.

Alternative: Direct Access Without ADB

If you don’t want to use ADB:

  1. Ensure your laptop and phone are on the same Wi-Fi network.
  2. Find your laptop’s local IP address:

    • On Windows:
     ipconfig
    

    Look for the IPv4 address under your active network.

    • On macOS/Linux:
     ifconfig
    
  3. On your phone, enter your laptop’s IP address with port 80 in the browser:

   http://192.168.x.x
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

  • ADB Connection Issues:

    • Ensure your phone is on the same network as your laptop.
    • Restart ADB server:
    adb kill-server
    adb start-server
    
  • Port Forwarding Not Working:

    • Check if your server is running properly on port 80.
    • Verify your phone’s local port (127.0.0.1:8080) is forwarded to the laptop.

By following these steps, you can easily access your laptop’s server from your phone wirelessly!

Top comments (2)

Collapse
 
srchip profile image
Ranuka Perera

What scenarios would we want to use adb to access a server over using the IP:port directly?

Collapse
 
ktauchathuranga profile image
Ashen Chathuranga

i recently implemented api fetched website that has PWA, you cant test your PWA application in your phone, unless you have https connection. so by doing this i was able to test my PWA feature without having to do any messy stuff...