//Init variables. var count = 0; //Called when application is started. function OnStart() { //Check wifi is enabled. ip = app.GetIPAddress(); if( ip == "0.0.0.0" ) { app.ShowPopup( "Please Enable Wi-Fi" ); app.Exit(); } //Prevent wifi from powering down. app.PreventWifiSleep(); //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(s)\n\n" + ip +":8080"; txt = app.CreateText( s, 0.8, 0.3, "AutoScale,MultiLine" ); txt.SetTextSize( 22 ); lay.AddChild( txt ); //Create a text label and add it to layout. txtMsg = app.CreateText( "", 0.8, 0.3, "AutoScale,MultiLine" ); txtMsg.SetTextSize( 22 ); lay.AddChild( txtMsg ); //Create a 'Send Message' button. btn = app.CreateButton( "Send Message", 0.4, 0.1 ); btn.SetMargins( 0, 0.05, 0, 0 ); btn.SetOnTouch( SendMessage ); lay.AddChild( btn ); //Add layout to app. app.AddLayout( lay ); //Create and run web server on port 8080. serv = app.CreateWebServer( 8080 ); serv.SetFolder( "/sdcard/DroidScript/Web Sockets" ); serv.SetOnReceive( serv_OnReceive ); serv.Start(); //Start timer to show WebSock connections. setInterval( ShowConnections, 3000 ); } //Show who is connected. function ShowConnections() { var clients = serv.GetWebSockClients(); if( clients.length > 0 ) { //Make a list of clients. var list = ""; for( var i=0; i