HttpServer and B4X

Star-Dust

Expert
Licensed User
Longtime User
Since for the moment I am forced into the home, I am working to create an Http server for B4i and completely in B4i (I don't know objective c)

I'm well under way and it seems to be working. At least the basic version. Now refine aspects like, Header, Parameter, Cookies. I think I will be able to add the Digest authentication system which I have already managed to implement in B4A.

For the moment I don't have much to show, just a little bit of code but not very meaningful. I have no videos at the moment, but I hope to be able to release an ALFA version towards the end of the week or at least a video demonstrating how it works.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
 
    Private Svr As Server
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
 
    Svr.Initialize(Me,"Svr")
    Svr.Start(51051)
End Sub

Private Sub Svr_Handle(req As ServletRequest, resp As ServletResponse)
    resp.SetHeader("Content-Type","text/html")
    resp.Write($"HtmlText=$"<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<h1>This is a static page</h1>
<a href='/'>Back</a>
</body>
</HTML>"$)
End Sub
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Here I have published the first beta version
 

Star-Dust

Expert
Licensed User
Longtime User
will it be for all platforms?
aHttpServer
jHttpServer
For other platforms it already exists, it was missing only for B4i
 

Star-Dust

Expert
Licensed User
Longtime User
They are internal libraries you don't have to download them.
For B4J use jserver for B4A HttpServer.
 

Star-Dust

Expert
Licensed User
Longtime User
example b4j

example b4a
 

Star-Dust

Expert
Licensed User
Longtime User
I've finished testing and added Digest authentication.

Now I have a full version of iHttpServer, I'm in the final stage of testing, but everything seems to work fine.

The only problem I had was with the md5 algorithm. The iEncryption library returns an all uppercase result. The B4A version of MD5 returns lowercase. The browser calculates the MD5 hash in lowercase.
It took hours to figure this out, but I finally solved the problem.

Also I have extended the HttpServer (B4A) library for Digest authentication.

I am considering if and how to distribute the libraries. Maybe I'll make a free but limited version to distribute on the forum
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I ask the experts of the Apple world for an opinion.

Do you think Apple would accept a web server application for mobile devices on the store or would it go against some rule?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
FWIW, there are such apps in the app store:

 

Star-Dust

Expert
Licensed User
Longtime User
Thank's 😄
 

Star-Dust

Expert
Licensed User
Longtime User
I continue this thread since it has already begun on the subject.

I am carrying out my iHttpServer project, I had to face several technical problems of transmission, encoding, decoding, data extraction of text and generic data in bytes.
Mainly for inexplicable reasons different behaviors in the release version, debug and debug step by step.
But also data reception events that are not raised.

see here:

And here

Now I have concluded the basis for a working http server. But it seemed incomplete, jQuery was missing which seem related to webSocket.
I always thought the webSocket was the same as the http connection but it doesn't close, it stays open. Nothing could be more wrong, it is a separate protocol that starts from the normal http.

So I have been studying the ws protocol for days.
https://tools.ietf.org/html/rfc6455

Poor knowledge of English didn't help me, but I finally understood the protocol.
In the next few weeks I hope to release a fully functional webSocket server.

Although it will never be at Jetty Server level for me it is a win because made entirely in B4I with no wraps in the obj-c code
 

Star-Dust

Expert
Licensed User
Longtime User
This morning I have a few hours free, I started to implement the webSocket .... let's see if I can.

1615442030151.png



I found an old VB6 code written by me 10 years ago for a Proxy Sock4 server ... who knows maybe if I remember the logic I'll put it back on for B4X
 

Star-Dust

Expert
Licensed User
Longtime User
First results with websocket.
I'm working on Erel's example, ServerExampleNoMySQL.

I simulated the existence of jQuery (which I have to build it from scratch) by inserting some basic function ... and echoing the result.


1615912796114.png


I've been banging my muzzle for two weeks now and the connection apparently dropped for no reason. Then I identified an error in the transmission of the Bytes of the payload length ..... two wasted weeks 😭😭😭😭😭
 

rabbitBUSH

Well-Known Member
Licensed User
Poor knowledge of English didn't help me
Nothing wrong with your English - I just had look - because its this time of night and I must be feeling perverse - just like that sort of document - and I've done quite a bit of technical editing over the years - who ever writes those documents PHEW - hats off to you for interpreting them PHEW. 😅

Thanks for all that you do for the forum .... 🖖
 

Star-Dust

Expert
Licensed User
Longtime User
From a first analysis it seems that jquery transform commands into Json strings which are then interpreted by the client thanks to JavaScript and Ajax functions.
It also generates and raises events within the server according to the strings received from the client.
It doesn't seem to be complicated to make, but we'll see better as I put my hand to it.

At this point the development I'm convinced that it could become a cross-platform b4xlib library.
 

Star-Dust

Expert
Licensed User
Longtime User
Update. Completed websocket and add jQueryelement.
Still missing a few small things of Jquery and cookies.
JQueryElement, I wrote it from scratch and the implementation will be different and also the name since it is not in Java .. it will be called QueryElement

video2.gif


It took me 2 months and 3 days
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Thanks, in a few days I will complete the examples and publish them.
 
Top