User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

built_in:webserver

This is an old revision of the document!


Table of Contents

WebServer control

Methods

Method Description
WebServer.AddServlet( p1,callback )
WebServer.SendText( txt )
WebServer.SetFolder( folder )
WebServer.SetResponse( text )
WebServer.Start()

Example

(Example taken from the DroidScript sample section)

//Called when application is started. 
function OnStart() 
{ 
	//Check wifi is enabled. 
	var ip = app.GetIPAddress(); 
	if( ip == "0.0.0.0" ) {  
		app.ShowPopup( "Please Enable Wi-Fi" );  
		app.Exit(); 
	} 
	//Create a layout with objects vertically centered. 
	lay = app.CreateLayout( "linear", "VCenter,FillXY" );	 
 
	//Create a text label and add it to layout. 
	var s = "Type the following address into your" +  
			" browser\n\n" + ip +":8080"; 
	txt = app.CreateText( s, 0.8, 0.5, "MultiLine" ); 
	txt.SetTextSize( 22 ); 
	lay.AddChild( txt ); 
 
	//Add layout to app.	 
	app.AddLayout( lay ); 
 
	//Create and run web server. 
	serv = app.CreateWebServer( 8080, "Upload,ListDir" ); 
	serv.SetFolder( "/sdcard/DroidScript" ); 
	serv.AddServlet( "/message", OnServlet ); 
	serv.Start(); 
} 
 
//Handle servlet requests. 
function OnServlet( request, info ) 
{ 
	serv.SetResponse( "Got it!" ); 
	app.ShowPopup(  info.remoteAddress + " says: " + request.msg ); 
} 
built_in/webserver.1427031717.txt.gz · Last modified: 2015/03/22 21:41 (external edit)