Android Tutorial Embed an Http Server in your Android Application

Status
Not open for further replies.

bernd33

New Member
Licensed User
Longtime User
Thanks for the quick answer.

The Chatexample is a automatic reload of the whole page every 5 Seconds? Sorry, but that is what I will prevent and the reason why I ask for Websockets.

Maybe I'm wrong but I think with Websockets it's possible to establish a bidirectional Server/Client realtimecommunication. So a "server part/program" can send new Values/Events/Whatever to the client and the Client will update only a part of the Webpage without reload the whole page.

In this case Server means Webserver Jetty and client mens Browser/IE/Crome/Safari.

But as I said. I'm new to this stuff and maybe I'm complete wrong


Regards, Bernd
 

bernd33

New Member
Licensed User
Longtime User
Hi,

two more little question Where is the httpdoc-rootpath? Is security like password/session implemented?

1.) Other Webservers like apache or iis have a rootpath for the html-documents. Where can I find this path?
I played arround with the httpserver and I was able to add a picture wich is stored on my Sdcard onto a Webside.
Also in the example I can list all directorys and files from my devices. This makes me a bit nervouse because when the Webserver is running and somebody visits the webside, this person is able to access all files/folders from the device?
1.1) Is the whole device the httpdoc-rootpath? If yes, is it possible to define a httpdoc-rootpath wich is the only accessable path from web side?

2.) Is any security function build in? Something like password/session?

The reason why I ask: With B4A and the httpserver I have a perfect combination to access/control my Atmega microcontrollers. No more needs to write a client program :sign0060: The androiddevice controlls/talks/querys by wlan the Atmega and a Webside shows me all I want on any device from anywhere on the world :icon_clap:

But... If the Webserver is accessable from the Internet, there should be a bit of security

Thanks a lot and regards, Bernd
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1) You should use Request.SendFile to server static files. They aren't served automatically. This means that it is up to you to decide which files will be served and how.

2) Note that your device will not be accessible from the internet. Unless you configure it as explained here: No-IP Android client - Access your device over the internet

You can easily implement a simple password / username check.
 

jgbozza

Member
Licensed User
Longtime User
When using the httpserver, the first remote request takes too long to fire the HandleRequest event. Once it's fired, the next requests go quickly.

If I don't send any request for a certain time, when I do it again it takes the same amount of time to fire the event as if I was doing it for the first time

Is that any issue with my WiFi networ? Is there any parameter that I can set in the software to avoid this response delay ?:sign0148:

I measured the time and it is always 30 seconds prior to fire the event!
 
Last edited:

jiangws

Member
Licensed User
Longtime User
Could I use css at template.html?

It's great chat program!

But it's diffucult to input characters at mobile phone. Could I use css at template.html? I want to put at apk, where to put and how to use it?

Thanks.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Very very interesting library.

This library is in my app enanchements planning but I suppose that my B4A ver. 1.93 isn't compatible. Right?
 

luke2012

Well-Known Member
Licensed User
Longtime User

You mean to replace the entire statement with the SQL.ExecNonQuery statement ?
 

Mahares

Expert
Licensed User
Longtime User
How to Upload and Download Files From a HTTP Embedded server

I configured a Galaxy 7 inch tablet as a HTTP Server using Erel’s HTTP lib. I would like each of 4 other phones/tablets devices to upload to it text files or download from it text files. I tried the below code, but it is obviously incorrect. When I tried to connect to it from another device, it displayed the content of the text file located on the server (7 in Galaxy) DirRootExternal on the screen.

B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
   Response.SendFile(File.DirRootExternal,"daily.txt")
End Sub
What is the piece of code I need in the serverService module to upload to it or and download from it files.
Thank you for any tips, code, etc. that can bring a smile to a needy poor fellow.
 

metrick

Active Member
Licensed User
Longtime User
I got "Application not installed" on my Samsung Galaxy S Android version 2.3.3.
 

metrick

Active Member
Licensed User
Longtime User
Problem is solved with uninstall an app with the same name. Now the app forced closed when open.
Here is a paste from output logs.
** Activity (main) Create, isFirst = true **
Ip address: 192.168.1.103
** Activity (main) Resume **
** Service (serverservice) Create **
2013-07-28 06:46:23.795:INFO::jetty-7.x.y-SNAPSHOT
2013-07-28 06:46:23.883:INFO::started o.e.j.s.ServletContextHandler{/,null}
2013-07-28 06:46:23.889:WARN::FAILED BlockingChannelConnector@0.0.0.0:7777 FAILED: java.net.BindException: Address already in use
2013-07-28 06:46:23.890:WARN::FAILED org.eclipse.jetty.server.Server@4057cce8: java.net.BindException: Address already in use
serverservice_service_create (java line: 177)
 

alienhunter

Active Member
Licensed User
Longtime User
Thanks Erel

works like a charm

I modified a bit your code and I can have 2 Tables or more ...

AH
 

Attachments

  • html1.jpg
    201.2 KB · Views: 529
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…