B4J Question jServer websocket

wl

Well-Known Member
Licensed User
Longtime User
Hi,

I would like to have jQuery (when any of the JQuery events happen - click - change - ...) to call a generic method on the server with the JQuery event name as a first parameter (instead of automatically calling a sub with the corresponding name).

Is there a way to do so ?

I see how the code works (by decompiling jserver.jar), but I do not succeed in compiling my own version using the Simple Library Compiler. I would assume this is not supported, but I can still try to get some help ? :)

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
  • Like
Reactions: wl
Upvote 0

OliverA

Expert
Licensed User
Are you using this as your basis? https://www.b4x.com/android/forum/threads/server-building-web-servers-with-b4j.37172/

Any of the WebSocket examples have a file named b4j_ws.js that used by the underlying html file to create a websocket connection the server. Look at the b4j_raiseEvent function. You can use it to just call a single method in your B4J code and pass to it any parameters that you want. That's what ABMaterial uses to call the centralized page_parseevent method (a single entry point for events generated by the page and passed on to the B4J WebSocket handler).
 
  • Like
Reactions: wl
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
why making it complicated?


I knew this answer would be coming :)

Reason is I'm writing a webserver based on Jetty and using Andy's great jBasicLib as server side scripting language (see: https://www.b4x.com/android/forum/t...interpreter-library.101471/page-2#post-727302). Now I would like to add websockets to the application as well. I was thinking of the clientside JQuery to call this generic B4J sub that would dispatch it to the corresponding jBasicLib's subs...

I could of course make my own JSON data to be send back and forth between the browser and the server side code and dispatch it from there ...

PS: the above reason is also why I decompiled existing JARs' in a search for a generic callsub method with a variable number of params wrapped inside an object array: I found out it existed as CallSub4 (that was used for CallSub, CallSub2, CallSub3) but that it was made private :)

Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
PS: the above reason is also why I decompiled existing JARs' in a search for a generic callsub method with a variable number of params wrapped inside an object array: I found out it existed as CallSub4 (that was used for CallSub, CallSub2, CallSub3) but that it was made private
There is a reason why it is private. Trying to access it directly will only be a waste of time.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Thanks for your reply !
I created a separate "library" with the (copied) code of callsub4 and as far as I can see currently it seems to work. Am I missing something important ?
The reason I needed this was that I am passing parameters between jBasicLib subs and B4j code and because of a distinct split of code in different classes (dispatching the implementation of methods) it was much cleaner/lesser work to be able to work with CallSub4.

PS: Many thanks for your excellent work !
 
Upvote 0
Top