B4J Question WebServer - a Client's routine does not run

LucaMs

Expert
Licensed User
Longtime User
I get a strange behavior.

The server (b4j) runs some routines on the client (device) in the right way.
For example:
B4X:
ws.RunFunction("RaisedByServer_NewNickOK", ArrayAsObject(Nick))
ws.Flush

In the case in which the routine is not present in the client code, I rightly get an error.

Only in one of these calls, the routine of the client does not run and I do not get error messages.

The method of the call is identical and also the modules are the same!

SERVER - wshPlayer
B4X:
Private Sub RunOnClient_NewNickOK(Nick As String)  '  <---- THIS IS OK
    ws.RunFunction("RaisedByServer_NewNickOK", Array As Object(Nick))
    ws.Flush
End Sub

Public Sub RunOnClient_PlayerJoinsRoom(msg As String)
Log("RunOnClient_PlayerJoinsRoom") ' <--- I get this log
    ws.RunFunction("RaisedByServer_PlayerJoinsRoom", Array As Object(msg))
    ws.Flush
End Sub


CLIENT - PlayerHandler
B4X:
Public Sub RaisedByServer_NewNickOK(Params As List)  ' <---- THIS IS OK, RUNS
    Private Nick As String = Params.Get(0)
    CallSubDelayed2(CallBack, EventName & "_NewNickOK", Nick)
End Sub

Public Sub RaisedByServer_PlayerJoinsRoom(params As List)
Log("RaisedByServer_PlayerJoinsRoom") ' <--- I DON'T get this log
End Sub


I realize that this explanation is poor; on the other hand I can not post both projects.





I hope this has happened to you
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Perhaps I'm wrong in this regard.

In the device I have an activity in which there is this call:
Main.wshPlayer.RoomSelected (ID)

So wshPlayer is declared as public.


[P.S. Obviously, the Main activity is not active at that time, but its public variable should be accessible, or not?]

[I answer to myself: yes, it is available]
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Yes, the problem is that call (Main.wshPlayer.RoomSelected (ID)).

If I use CallSubDelayed2 to call a routine of Main which in turn runs the wshPlayer's call, everything works.

(But I do not want to go back to Main, so everything is planned badly)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Sounds like you need a Service to manage the communication.

Good idea, thanks. I'll try it (when I have thought better of the whole structure, how and if share the PlayerHandler object instance)


[P.S. I guess you mean this, sharing the websocket handler through a service, or not? I have to try to look at things from a distance, if you know what I mean.
I have to clarify my few ideas.]
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Sounds like you need a Service to manage the communication.

... the communication between? Within the client, between the websocket handler and the activities?

I have not ever used the service modules, but I remember something about their state (the foreground is less likely to be killed).

But in this case I should turn the service on a permanent active state and, I suppose, there would be a strong demand on battery power - in service "listening" and websocket listening.

But perhaps I misunderstood your suggestion.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
A service by itself will not have any effect on the battery. It will allow you to intercept events when the main activity is not visible.

Since I have not used them, I have to re-read their documentation (immediately).

You probably mean that they do not consume until they are started.
I think that if they remain in listening for an event, should consume resources (but it is better that I read )


Thanks, Erel.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
A service by itself will not have any effect on the battery. It will allow you to intercept events when the main activity is not visible.
Only six years later ? ? ...

Only now I have "discovered" that by calling a routine of an Activity that is not in the foreground, using a CallSubDelayed placed in a service module, the Activity is destroyed and recreated. If, on the other hand, the CallSubDelayed is inside an Activity (in foreground, obviously) the destruction does not occur.

This could be a good reason to switch to B4XPages.

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