开发者

Web Server for Android

Is it possible to host a web server within an Android phone itself? Similar to Apa开发者_运维技巧che. I want to access the web server from the mobile browser itself.

Couldn't find any reference online. Is this possible?

Thanks in advance


Short: yes. If you are looking at code, check out the org.apache.http package. If you are looking at a ready app, check iJetty and kWS.


KSWEB — a suite for web development on the Android platform. It consists of: a web server, PHP programming language and the database MySQL. KSWEB allows you to organize a platform for running and debugging Web applications (sites) in your Android device. Working with the application is very simple. To start the server it is enough to run our application, select, if necessary, port and the root directory.

By default, KSWEB contains a fully functional configuration file of the server, PHP and MySQL. However, if you want something to change them, go to the server options and click on the item «INI Files». Configuration files will be moved to SD-card of your device at «/mnt/sdcard/ksweb/ini/», if available. If repeatedly clicking on the item settings «INI Files» KSWEB will use the internal configuration files.

What's in the plans?

  1. Review the requirements for the Android operating system, in particular reduce the requirements for the version of Android to run the application to 2.0;
  2. Add the ability to track the flow of errors arising when working with php and mysql;
  3. Move the log files on the server and mysql on sdcard;
  4. Extend the additional PHP libraries. For example, pdo_mysql;
  5. Move the database files to MySQL on sdcard.

https://play.google.com/store/apps/details?id=ru.kslabs.ksweb http://www.kswebserver.ru/


Atjeews android app server, small footprint, biggest advantage for me was jsp support.


I recently installed BitWeb which I recommend highly. I have a rooted phone with lends me a few more options (and I also recommend rooting if you haven't and plan on doing any server tinkering at all)

BitWeb is nice in that it includes a lighttpd server, a stripped down php engine and a stripped down mysql engine giving you a quick and dirty LAMP system with just one app. I use mine in conjunction with an sshd app to gain a busybox shell, I installed nano and use the ssh connection to do an sshfs share to edit content from my pc. Bitweb includes the ability to tweak the config settings for all three services, and I've even managed to get multiple Zend servers working on just the one little server with a little tweaking to the re-write rules and the application.ini settings.

https://play.google.com/store/apps/details?id=com.andi.serverweb&hl=en

If you want to see some of the config options I had to customize, I can either post them or respond via email with what I set up as well as some comments on the pitfalls I ran into along the way. (I recently posted one as a self-answered thread on here by the way, although it turned out not to be specific to the android platform but with lighttpd/Zend)

I'm just bummed that t-mobile/HTC appears to have no plans to upgrade my phone beyond Gingerbread as I understand some of the new android OS's have ways you can access some of the hardware (such as the cameras) from scripts or compiled code without a fuss. If I want to do it now, I either need to hard code my own interface to them or get a pre-roll app capable of doing it which really tasks my phone when running side-by-side with the web/mysql/php services.


I might be a last to answer this question but believe me, this is the simplest and latest answer in 2020 for those who need to start a webserver in Android and need to serve multiple clients without implementing any other third-party libraries.

Copy your HTML file into the assets folder of Android as server.html and declare the serverSocket as global in your class.

Run the below code inside a new thread.

try {
    serverSocket = new ServerSocket(8080);
    while (true) {
        final Socket socket = serverSocket.accept();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    PrintWriter os = new PrintWriter(socket.getOutputStream(), true);
                    String request = is.readLine();
                    Scanner scanner = new Scanner(getAssets().open("server.html"));
                    String response = scanner.useDelimiter("\\Z").next();
                    os.print("HTTP/1.0 200" + "\r\n");
                    os.print("Content type: text/html" + "\r\n");
                    os.print("Content length: " + response.length() + "\r\n");
                    os.print("\r\n");
                    os.print(response + "\r\n");
                    os.flush();
                    socket.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }).start();
    }
} catch (Exception ex) {
    ex.printStackTrace();
}

That's all your native Android Java (no third-party libraries implemented) webserver is live at port 8080.

If you want to use DB and POST requests, try to implement SQLite and WebSocket connections to make two-way communication.

https://developer.android.com/reference/java/net/ServerSocket


Check KSWEB and Bit Web Server, both using Lighttpd als server, php and support mysql.

i tried KSWEB, it works wonderfull, but i don't know yet how to use the modrewrite. but, it should be work. you can try the trial version of KSWEB before purchase it.

KSWEB costs a little bit more than Bit Web Server only 0,XX $. if you decided to buy it, post your experience here... i want to know too... :)

Bit Web Server

KSWEB


Till now I have seen all those applications are paid . And others doesn't have phpmyadmin. And I found finally one. You can have a look at kickweb server.

Android web server PHP/MySQL/PHPMyAdmin

Requirements

  • Internal memory should not be less than 50MB!
  • Minimum Android API 9 (GINGERBREAD)!

Features

  • Lighttpd 1.4.34
  • PHP 5.5.9
  • MySQL 5.1.62
  • MSMTP 1.4.31
  • phpMyAdmin 4.1.10
  • Nginx 1.5.11

Default Document Root (htdocs)

  • Path : /sdcard/htdocs/

Default URL

  • Address : localhost:8080

phpMyAdmin Informations

  • Address : localhost:10000
  • Username : root
  • Password :

MySQL Informations

  • Host : localhost
  • Port : 3306
  • Username : root
  • Password :

If you find trouble to make it working, you can see this video : https://youtu.be/3_m3vNGTp74


Yes, it is possible. May be not so complicated as Apache, but possible.

Look at Moto Phone Portal for example, it has web-server in its base. And there were several applications for this purpose in Market.


Servers Ultimate Pro, just 8 pounds. Include PHPAdmin, MySQL and ton of other servers. I am currently using it as proxy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜