B4i Library SD: iHttpServer (beta)

I started developing a version of the HttpServer Library for iOs. It is still a beta version and not complete, but already functional. You can start using it to test it. Includes WebSocket and QueryElement implementation
Digest Auth will be added in the future. I have arrived at a first version of the server that allows Digest authentication.
NEW: I have arrived at a first version of the server that allows Digest authentication. It is not included in the distributed version
It is entirely written in B4i, it depends on the iNetwork library

The library has been updated to be cross-platform and you can find it in this THREAD


iHttpServer

Author:
Star-Dust
Version: 0.72
  • QueryElement
    • Events:
      • change (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • click (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • dblclick (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • focus (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • focusin (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • focusout (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • keyup (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • mousedown (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • mouseenter (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • mouseleave (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • mousemove (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
      • mouseup (Resp As ServletResponse, Params As Map) ' QueryElement Event Click
    • Fields:
      • Event_change As NSString*
      • Event_click As NSString*
      • Event_dblclick As NSString*
      • Event_focus As NSString*
      • Event_focusin As NSString*
      • Event_focusout As NSString*
      • Event_keyup As NSString*
      • Event_mousedown As NSString*
      • Event_mouseenter As NSString*
      • Event_mouseleave As NSString*
      • Event_mousemove As NSString*
      • Event_mouseup As NSString*
      • NoEvent As B4IMap*()
    • Functions:
      • Class_Globals As NSString*
      • CreateEvent (ObjectName As NSString*, Event As NSString*, OtherEvent As B4IMap*()) As B4IMap*()
      • Eval (Script As NSString*, Params As B4IList*) As NSString*
      • EvalWithResult (Script As NSString*, Params As B4IList*) As NSString*
      • Initialize (ba As B4I*, Response As B4i_servletresponse*) As NSString*
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As BOOL
        Verifica se l'oggetto sia stato inizializzato.
      • RunFunction (function As NSString*, ID As NSString*, Params As B4IList*) As NSString*
        Param = list or array: array as Object is wrong - array as Map is correct
      • RunFunctionWithResult (function As NSString*, ID As NSString*, Params As B4IList*) As NSString*
      • RunMethod (Method As NSString*, ID As NSString*, Params As B4IList*) As NSString*
        Param = list or array: array as Object is wrong - array as Map is correct
      • RunMethodWithResult (Method As NSString*, ID As NSString*, Params As B4IList*) As NSString*
        Param = list or array: array as Object is wrong - array as Map is correct
      • SelectElement (ID As NSString*) As NSString*
      • SetCommand (etype As NSString*, Method As NSString*, property As NSString*, ID As NSString*, Params As B4IList*, Arg As B4IList*) As NSString*
      • SetCSS (id As NSString*, Params As B4IList*) As NSString*
      • SetHtml (id As NSString*, Params As B4IList*) As NSString*

        Public Sub SetHeight (Value As String)
        End Sub
      • SetPropriety (Property As NSString*, Value As B4IList*) As NSString*
    • Properties:
      • AutomaticEvents
  • ServletRequest
    • Fields:
      • CharacterEncoding As NSString*
      • ConnectionAlive As BOOL
      • ContentLength As Long long
      • ContentType As NSString*
      • ID As NSString*
      • LogActive As BOOL
      • LogFirstRefuse As BOOL
      • MultipartFilename As B4IMap*
      • RequestCookies As B4IMap*
      • RequestHeader As B4IMap*
      • RequestParameter As B4IMap*
      • Timeout As Long long
    • Functions:
      • Class_Globals As NSString*
      • Close As NSString*
      • Connected As BOOL
      • GetHeader (Name As NSString*) As NSString*
      • GetHeadersName As NSObject*
        can be used to iterate over Header
        Example
        <code>
        For Each Name As String In ServletRequest.GetHeadersName
        Log("Value = " & ServletRequest.GetHeader(Name))
        Next</code>
      • GetInputStream As B4IInputStream*
      • GetMethod As NSString*
      • GetRequestHOST As NSString*
      • GetRequestURI As NSString*
      • GetWebSocketCompressDeflateAccept As BOOL
      • GetWebSocketCompressGzipAccept As BOOL
      • GetWebSocketMapData As B4IMap*
      • GetWebSocketStringData As NSString*
      • Initialize (ba As B4I*, CallBack As NSObject*, EventName As NSString*, Sck As B4ISocketWrapper*) As NSString*
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As BOOL
        Verifica se l'oggetto sia stato inizializzato.
      • ParameterMap As B4IMap*
      • RemoteAddress As NSString*
      • RemotePort As Int
  • ServletResponse
    • Fields:
      • CharacterEncoding As NSString*
      • ContentLenght As Int
      • ContentType As NSString*
      • Status As Int
    • Functions:
      • Class_Globals As NSString*
      • Close As NSString*
      • Connected As BOOL
      • Initialize (ba As B4I*, Req As B4i_servletrequest*, ast As B4IAsyncStreams*, Sck As B4ISocketWrapper*) As NSString*
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As BOOL
        Verifica se l'oggetto sia stato inizializzato.
      • ResetCookies As NSString*
      • SendFile (Dir As NSString*, fileName As NSString*) As NSString*
        don't use DirAssets
      • SendFile2 (Dir As NSString*, fileName As NSString*, Content_Type As NSString*) As NSString*
      • SendNotFound (filenameNotFound As NSString*) As NSString*
      • SendRaw (Data As Unsigned char()) As NSString*
      • SendRedirect (Address As NSString*) As NSString*
      • SendString (Text As NSString*) As NSString*
        sending text with Header
      • SendWebSocketBinary (Data As Unsigned char(), Masked As BOOL) As NSString*
      • SendWebSocketClose As NSString*
      • SendWebSocketPing As NSString*
      • SendWebSocketPong As NSString*
      • SendWebSocketString (Text As NSString*, Masked As BOOL, Compressed As NSString*) As NSString*
        Cmpressed as Deflate=zlib, gzip, none - (set always none)
      • SetCookies (Name As NSString*, Value As NSString*) As NSString*
        Set Cokies values on Browser
      • SetHeader (Name As NSString*, Value As NSString*) As NSString*
      • Write (Text As NSString*) As NSString*
        Sending text without header to dynamically send more text after the SendString
    • Properties:
      • OutputStream As B4IOutputStream* [read only]
      • Query As B4i_queryelement* [read only]
  • httpServer
    • Events:
      • Handle (req As ServletRequest, resp As ServletResponse)
      • HandleWebSocket (req As ServletRequest, resp As ServletResponse)
      • NewConection (req As ServletRequest)
      • SwitchToWebSocket (req As ServletRequest, resp As ServletResponse)
      • UploadedFile (req As ServletRequest, resp As ServletResponse)
      • UploadProgress (resp As ServletResponse, Progress As Float) ' Progress = 0-1
      • WebSocketClose (CloseCode As Int, CloseMessage As String)
    • Fields:
      • DigestAuthentication As BOOL
      • DigestPath As NSString*
      • htdigest As B4IList*
      • IgnoreNC As BOOL
      • realm As NSString*
      • Timeout As Int
    • Functions:
      • Class_Globals As NSString*
      • GetMyIP As NSString*
      • GetMyWifiIp As NSString*
      • Initialize (ba As B4I*, CallBack As NSObject*, EventName As NSString*) As NSString*
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As BOOL
        Verifica se l'oggetto sia stato inizializzato.
      • Start (Port As Int)
        eg. Start(51051)
      • Stop As NSString*

Sample
ezgif.com-optimize.gif video2.gif
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
great!! now the example is working.

can i set a static folder to send my whole site? including css/js files?
As I wrote it is still under development but will have this function.
Now you can receive requests and reply with text, in the future you can also send files.

Unfortunately I don't have time, I have many ideas and little time.
 

Star-Dust

Expert
Licensed User
Longtime User
I am happy to present the most important update of this library. It doesn't have all the features expected on a server but a significant step has been taken.

Update 0.50
  • Added SendFile
  • Updated the example

Try
After starting the example on the mobile device, you can access the page from the browser of your pc by indicating the ip address of the mobile device and the port chosen. (better if it is on a local network)
For example: http://192.168.1.100:51051

ezgif.com-optimize.gif
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Looks amazing. Will test it later. How much is the paid cersion?
There is no paid version. It is not a DEMO version but BETA.
It is still under development and is free, I assume it will remain free because I believe it is a basic library of a language.
 

ilan

Expert
Licensed User
Longtime User
hi Start-Dust, i have tried it and i see the huge step you did. although i am getting lots of bugs. for example if i type the ip to connect sometimes i get the page rendered and sometimes i get the HTML Text printed instead.

another thing i noticed is that if i have a page that has a css file linked the html is not able to load it but if i disconnect the connections (stop the debug process) the page loads the css file. can it be that you send the css file after you send the index.html and thats why index.html doesnot find the css file? maybe the index.html should be sent at the end after all files have been sent.

i understand that it is a demo and still in development and that you also dont have much time but if you like i would love to join the development and try to help you finish the project. if you are interested let me know :)

thank you for your great job. i will send you a beer to cool down ;)
 

Star-Dust

Expert
Licensed User
Longtime User
hi Start-Dust, i have tried it and i see the huge step you did. although i am getting lots of bugs. for example if i type the ip to connect sometimes i get the page rendered and sometimes i get the HTML Text printed instead.

another thing i noticed is that if i have a page that has a css file linked the html is not able to load it but if i disconnect the connections (stop the debug process) the page loads the css file. can it be that you send the css file after you send the index.html and thats why index.html doesnot find the css file? maybe the index.html should be sent at the end after all files have been sent.

i understand that it is a demo and still in development and that you also dont have much time but if you like i would love to join the development and try to help you finish the project. if you are interested let me know :)

thank you for your great job. i will send you a beer to cool down ;)
I have to look into this before I answer.

As a matter of fact, I can answer that the server always sends only the source and the browser that does the rendering. So there is some error where the browser translates the html page to txt. It will be less of a problem.

For CSS, the server does not send before or after, but only when the browser requests it. That is, after having 'read' the html source, it becomes aware of the presence of a CSS file and requests it from the server. I have not tested this, as soon as possible I will let you know.

Thanks for the offer of help, I can't work with 4 hands and I should explain the sources and reasons for some choices, even for this it takes time unfortunately. But I'll think about your proposal. ;)

Thanks for the beer, only after drinking it I'm no longer lucid and I feel sleepy :rolleyes::oops:o_Oo_O
 

Star-Dust

Expert
Licensed User
Longtime User
hi Start-Dust, i have tried it and i see the huge step you did. although i am getting lots of bugs. for example if i type the ip to connect sometimes i get the page rendered and sometimes i get the HTML Text printed instead.
Does this problem give you in the example? On which html page?

Send me privately an example that I can try with CSS where it introduces you to the flaw
 

Star-Dust

Expert
Licensed User
Longtime User
Update 0.06
 

Star-Dust

Expert
Licensed User
Longtime User
Update 0.65
  1. Fix Bugs
  2. Improved the SendFile method by including MIME related to file types
  3. Improved SendString (sending with Header) and added SendWrite (without header to dynamically send more text after the SendString)
According to the roadmap, GetUploadFile is missing
There will probably be no TempFolder to upload files to send directly from an internal folder
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update 0.66
  1. Fix Bugs
  2. Support for UpLoad files
  3. I change the name of the main class from Server to httpServer to avoid confusion with other libraries
  4. Update Example
1614807235766.png
 
Last edited:

ilan

Expert
Licensed User
Longtime User
Update 0.66
  1. Fix Bugs
  2. Support for UpLoad files
  3. I change the name of the main class from Server to httpServer to avoid confusion with other libraries
  4. Update Example

really nice @Star-Dust
i tested the file upload function and on chrome it works fine.
on firefox after i upload 1 file i have to press F5 to refresh the site to be able to upload another file.
in chrome i dont need to do that but firefox i am not able to upload 1 file after another if i dont refresh the site again.
 

Star-Dust

Expert
Licensed User
Longtime User
really nice @Star-Dust
i tested the file upload function and on chrome it works fine.
on firefox after i upload 1 file i have to press F5 to refresh the site to be able to upload another file.
in chrome i dont need to do that but firefox i am not able to upload 1 file after another if i dont refresh the site again.
Okay, I'll do some tests. Each browser has a different answer.
 

Star-Dust

Expert
Licensed User
Longtime User

ilan

Expert
Licensed User
Longtime User
thank you very much @Star-Dust. i managed to make a working example on a dynamic web app that can be modified from the b4i server.

video:


awesome library, keep improving it!
this may be the solution for b4i web server we all look for.

on chrome it works fine, firefox needs to refresh after 1 file upload (as already mentioned above)
:)

btw this is a real phone (iphone 11) connected to Reflector running on my windows 10. so it is really working!!! :D:D:D

EDIT: short explanation of the purpose of this webserver. you run a server on your ios device -> connect to the device by entering the wifi IP (locally only) and now you can download or upload any file you want to your ios device from any web browser. very simple and powerful way of transfering files from/to your ios device.
 
Last edited:

ilan

Expert
Licensed User
Longtime User
just noticed that in release mode the app crashes each time i use the upload function. in debug mode it is working fine but in release mode the app crashes.
 

Star-Dust

Expert
Licensed User
Longtime User
just noticed that in release mode the app crashes each time i use the upload function. in debug mode it is working fine but in release mode the app crashes.
It was fixed in the latest update.
 
Top