B4J Question ABMaterial and raised event from handler

micro

Well-Known Member
Licensed User
Longtime User
Hi
I have in Main this code:
B4X:
srv.AddHandler("/conn1", "conn1", False) 'From devices
myApp.StartServer(srv, "srv", 51042)

In conn1 module:
B4X:
Sub Class_Globals
    Private sharemodule As MainPage 'the first Page show on the browser
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim read As Map
    Dim result As Map
    read.Initialize
    result.Initialize
    read = ReadObject(req.InputStream)
    result =  CallSub2(sharemodule, "SetControls", read)
    If result.IsInitialized Then
    .........
    .........
End Sub

In MainPage the Sub
B4X:
Public Sub SetControls(mp As Map) As Map
    ........
End Sub
is never raised.
Why?
 

alwaysbusy

Expert
Licensed User
Longtime User
just reading a bit further into the source code you've send me, shouldn't it be:

B4X:
'WebSocket class
Sub Class_Globals
    ...
    Private targetmodule As object
End Sub

Public Sub Initialize(target as object)
    targetmodule = target  
   ...
End Sub


Sub Handle(req As ServletRequest, resp As ServletResponse)
    ...

    result =  CallSub2(targetmodule, "SetControls", read) 
   
    ...
End Sub
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Thanks Alain for your answer
It seems more complicated than usual.
I moved addHandler in ABMApplication with the way you suggested
B4X:
 srvr.Initialize(srvrName)   ' Here is the initialize of the server
srvr.AddWebSocket("/ws/" & AppName, "ABMApplication")
srvr.AddHandler("/" & AppName & "/MainPage/conn1", "conn1", False) 'lineax
but not working, the Sub Handle in conn1 is raised only with
B4X:
srvr.AddHandler("/conn1", "conn1", False) 'lineax
but the CallSub2 not work.....same problem as before.
I also added to MainPage the reference to "conn1" but Sub Handle in conn1 is never activated.

It seems to work only in this way:
in ABMApplication:
B4X:
 srvr.Initialize(srvrName)   ' Here is the initialize of the server
srvr.AddWebSocket("/ws/" & AppName, "ABMApplication")
srvr.AddHandler("/conn1", "conn1", False) 'lineax
In the MainPage i have create the public targetmodule object and initializes this with "Me"
In conn1 create a reference to MainPage and and just so CallSub2 work.....
but it does not know if the procedure is correct, in the sense if the code is perfect

Thanks to all.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…