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
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update rel 0.3
  • Fix bugs
  • Can see the remote ip address
  • Add TimeOut
  • DIgest authentication is disabled in this free version
 

Star-Dust

Expert
Licensed User
Longtime User
How to carry out the tests:
  1. 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

  2. Or using the CURL command from windows:

    For example: curl --location --request POST "http://192.168.1.100:51051" --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "device=mydevice" --data-urlencode "idConnection=000000002" --data-urlencode "command=CON" --data-urlencode "timeOutLimit=3600" --digest -u User:MyPassword -v
 

ilan

Expert
Licensed User
Longtime User
hi Star-Dust, i try to run your example but i am not able to build it. i am getting lot of errors.

 

Star-Dust

Expert
Licensed User
Longtime User
Dear Ilan,

I state that this library is still immature. It lacks methods: SendRedirect, SendFile, getUploadFile and other classes for managing connections. The whole is built in b4i and is not a wrap. So you are trying an experimental version.

After this premise, I can tell you that I just tried it and it works. Make sure you have changed the package name and point it to your CertificateFile and ProvisionFile. For the rest, I don't know what errors they are, I'm not that expert in iOs.

Are you using the example I provided without any changes?
 

Star-Dust

Expert
Licensed User
Longtime User
yes

the only change i did is package name and provisions file.
saw this in the error log you posted

Missing the file?
/Users/ilantetruashvili/Downloads/macserver70/UploadedProjects/<user id>/B4iProject/b4i_main.h:3:9: fatal error: 'iHttpServer.h' file not found
#import "iHttpServer.h"
^~~~~~~~~~~~~~~
1 error generated.
 

ilan

Expert
Licensed User
Longtime User
Missing the file?

yes you are right the .h file was missing. now i am able to compile the project. although when i enter the url i am getting a "Out of bounds..." error.

 

Star-Dust

Expert
Licensed User
Longtime User
yes you are right the .h file was missing. now i am able to compile the project. although when i enter the url i am getting a "Out of bounds..." error.
What is the request you made on the browser?
 

Star-Dust

Expert
Licensed User
Longtime User
The error is in data reception. The browser is sending an unexpected string as parameters.
Let me check and send an update.
 

Star-Dust

Expert
Licensed User
Longtime User
I can't reproduce the error. What browser did you use?
 

Star-Dust

Expert
Licensed User
Longtime User
my default browser is FireFox but i tried also on chrome and on IE all gave me the same error
Windows or Mac?
 

Star-Dust

Expert
Licensed User
Longtime User
how does the SendString function look like? can you post the code?
B4X:
astream.Write(Text.GetBytes("UTF8"))
 

Star-Dust

Expert
Licensed User
Longtime User
Update 0.04
  1. Fix Bug
  2. add SendRedirect
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…