Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Termux to set up HTTP server of mobile phone.

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to use Termux to set up a HTTP server for a mobile phone. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

How can mobile files, such as photos and videos, be downloaded to a desktop computer?

Ordinary users can use mobile phone lines to connect their phones to their computers. As a developer, a more convenient way is to set up a HTTP service on the phone and then access the phone from a desktop browser.

The editor explains how to use Termux to set up a HTTP server for a mobile phone.

What is Termux?

Termux is a Linux simulator for Android phones, which can simulate the Linux environment on the phone. It provides a command line interface that allows users to interact with the system.

It is an ordinary mobile phone App that can be downloaded and installed from the app store. You don't need root permission, you don't need to set it, and you can use it when you open it.

II. Environmental preparation

When you open Termux, it is a full-screen command-line interface. Although you can use your phone's touch keyboard to enter commands, it is recommended to use a Bluetooth keyboard.

The first step is to update the system to make sure you use the latest version.

# Connect to the remote repository to obtain package information $apt update# to update the locally installed package $apt upgrade

Step two, test the system.

# install sl package $apt install sl# run $sl

The above command installs the test package sl and runs it. If all goes well, a train order action picture will be displayed.

The third step is to access native storage.

Mobile App can only access its own data by default. If you want to access the storage of mobile phone, you need to request permission.

$termux-setup-storage

After executing the above command, a dialog box pops up asking if Termux should be allowed to access mobile storage, and click "allow".

This will generate a story subdirectory under the current directory, which is the symbolic link stored by the phone, and the later download file will be downloaded to this directory.

III. Software package management

In addition to the apt command, Termux also provides the pkg command for package management.

# install package $pkg install [package name] # Uninstall package $pkg uninstall [package name] # list all packages $pkg list-all

In fact, the bottom layer of pkg is apt, but apt update will be executed before running to ensure that the latest version is installed. Therefore, apt install sl is basically equivalent to pkg install sl.

A list of software packages supported by Termux can be seen here.

IV. Node.js

Next, install Node.js.

$apt install nodejs

After the installation is complete, you can run the JavaScript script. For example, create a new script hello.js.

/ / hello.jsconsole.log ('hello world')

Then, execute the script.

$node hello.jshello world V. Erection of Server

Now, run HTTP Server through Node.js.

First, install the npm module http-server.

$npm install-g http-server

Then, run Server.

$http-server

Normally, the command line will prompt that Server is already running on port 8080, and will also prompt for an externally accessible IP address.

For example, the LAN IP of the phone is 192.168.2.6, so if we visit http://192.168.2.6:8080 through the browser of the desktop computer, we can see the root directory of Termux. Go to the story subdirectory below and you can download the phone files.

If the phone and the computer are not on the same local area network, you can turn on the hotspot function of the phone, let the desktop computer surf the Internet through the hotspot of the phone, and then access the HTTP Server of the phone.

By the way, the following command can check the phone's IP address from the command line.

$apt install net-tools$ ifconfigVI, Python

Instead of using Node.js, it is possible to use other methods to set up HTTP Server. Let's demonstrate the method of Python.

$apt install python$ python-m http.server 8080

Then the desktop computer can access the mobile phone.

Termux is a very powerful tool, in addition to the above method, you can also set up an Apache server, or through other ways (FTP, SSH, Rsync) to access mobile phones, which will not be described in detail here.

The above is how to use Termux to set up the HTTP server of the mobile phone. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report