Extension: Simple Web Server

5456 views
Skip to first unread message

Juan Antonio

unread,
Jul 29, 2017, 2:15:13 PM7/29/17
to MIT App Inventor Forum
Hi friends,

this extension create a Simple Web Server.

Features and Restrictions:

1.- Only can serve one HTML file, this file is in SdCard, example in root SdCard: /mnt/sdcard/index.htm

2.- Also can serve a text

3.- File only with codes HTML, no images, It is posible externals link.


4.- This extension is a service, if you start this server, click back button mobile and run others apps, this server continue run.


5.- To stop this service, Click in Button1 or Button2 again, when stop service app is closed. With this code isn't posible stop service and continue run app. Button1 and Button2, start server and stop  "app & server".


6.- It Works in MIT COMPANION and installed (better installed).


7.- User must write in browser your local WiFi IP and port 8080, example: 192.168.1.5:8080


8.- My index.htm in only an HTML file example, to try copy in root SdCard (/mnt/sdcard/index.htm)


9. You can set a file (/mnt/sdcard/index.htm) and run server. Then close server-app. Run again server-app. Then set other file (/mnt/sdcard/other.htm) and run server again.


10.- Size extension only 13 KB.


Regards.



Juan Antonio Villalpando.


kio4.com






index.htm
com.KIO4_SimpleWebServer.aix

Taifun

unread,
Jul 29, 2017, 7:44:35 PM7/29/17
to MIT App Inventor Forum
what exactly is the advantage of using this extension compared to a webviewer component?
Taifun

Juan Antonio

unread,
Jul 30, 2017, 5:37:54 AM7/30/17
to MIT App Inventor Forum
Hi Taifun,

this is a web server, a web server serve web pages or files to users, in response to theirs requests.

WebViewer is a browser, as Chrome, Firefox,... to read htm pages or others files.

If you run this server in your app, others users from you local net, can read file in your /mnt/sdcard, example: /mnt/sdcard/file.htm

Others local users in theirs browsers in PC, mobile, tablet... can write your local IP, example: 192.168.1.5:8080 and read your page. (umm difficulty with english).

Tim Carter

unread,
Jul 30, 2017, 5:51:50 AM7/30/17
to MIT App Inventor Forum
Do you need to use Webviewer to see output of the webserver, you didn't show these blocks?

I presume you need a routine to grab the local IP on each use, but won't each device create its own server, or do you simply have one app for the server and another app to access the server from other devices?

Juan Antonio

unread,
Jul 30, 2017, 6:45:04 AM7/30/17
to MIT App Inventor Forum
Hi Tim,

when you run this extension in your app, you mobile is a local web server. You find you IP, is easy, example when run MIT COMPANION show your local IP. 

Then you say this IP others user, those user in browsers PC, Android, tablet,...example Chrome, Firefox, WebWiever... write your local IP, example 192.168.1.5:8080 and get you file.

If you need static IP number in your mobile, you can set your router. MAC --------> IP.




Tim Carter

unread,
Jul 30, 2017, 7:04:21 AM7/30/17
to MIT App Inventor Forum
Thanks Juan, it is making sense now :)

Juan Antonio

unread,
Jul 30, 2017, 7:31:07 AM7/30/17
to MIT App Inventor Forum
Hi Tim,

this version with a new block to get WiFi IP. 


com.KIO4_SimpleWebServer.aix

Abraham Getzler

unread,
Jul 30, 2017, 12:32:23 PM7/30/17
to MIT App Inventor Forum

Abraham Getzler

unread,
Jul 30, 2017, 12:46:58 PM7/30/17
to MIT App Inventor Forum
I imagine this server would be useful for local chat without SMS or BlueTooth,
assuming local WiFi.  Clients of the server would need to poll it periodically.

ABG

Juan Antonio

unread,
Jul 30, 2017, 1:06:56 PM7/30/17
to MIT App Inventor Forum
Thank you Abraham,

I thought in a chat, perhaps if web page refresh in client by HMTL code http-equiv=”refresh” content="15" poll automatic


But principal restriction of this code is: you can't stop server and continue app. Whenever stop server, close app.

Juan Antonio

unread,
Aug 7, 2017, 7:56:30 AM8/7/17
to MIT App Inventor Forum
Hi friends, 

this is a new version com.KIO4_SimpleWebServer.aix extension, 7/august/2017

- Fixed Stop server. Now when Stop server app doesn't close.

- To try example, please download files index.htm and baile.htm and copy in your: /mnt/sdcard/

- This simple web server can serve text but not images, but works with hotlink.

- Hotlinks works in PC browsers, but doesn't work for me in Chrome mobile.


- Regards.


Juan Antonio Villalpando


kio4.com



index.htm
baile.htm
SimpleWebServer2.aia
com.KIO4_SimpleWebServer.aix

MiuMiu

unread,
Aug 8, 2017, 9:40:46 PM8/8/17
to MIT App Inventor Forum
hi,it is very good aix,and could you add a event to app,in the event can get the url path,then can analysis the url path to repose different to the client.

Juan Antonio

unread,
Aug 9, 2017, 5:09:24 AM8/9/17
to MIT App Inventor Forum
Thanks MiuMiu, I'll try that.


btw. in this post a chat example by this SimpleWebServer:







Message has been deleted

Patryk F

unread,
Dec 15, 2019, 12:53:48 PM12/15/19
to MIT App Inventor Forum
Hi Juan Antonio.  Could you create an extension that would create a server at http://127.0.0.1:50099/api? I would like to read localhost from http://lwpm.eu. It sends data to 127.0.0.1:50099/api
Reply all
Reply to author
Forward
0 new messages