B4J Question sending data using the B4J WebSockets client library and jquery

monic

Active Member
Licensed User
Longtime User
Hi all, I have downloaded the websocket project and have embedded into a test app for android, but I just need a pointer with the client/server side script (
B4J WebSockets client library)
I want to modify the sample script to just use jquery to inject data to the websocket connection instead of using the button that was provided in the demo.

https://www.b4x.com/android/forum/threads/custom-websocket-based-push-framework.40272/

B4X:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="b4j_ws.js"></script>

<script>
$( document ).ready(function() {
b4j_connect("/push/ws");});
</script>

<script>
b4j_raiseEvent("btnsend", {result: theResult}) //the event name should be lower cased
b4j_ws.send(JSON.stringify({"type":"data","data":"wwww"}));
</script>
I got these from the frames in the demo provided:

B4X:
{"type":"event","event":"btnsend_click","params":{"which":1,"target":"btnsend","pageX":31,"pageY":19,"metaKey":false}}

{"id":"#txt","method":"val","etype":"runmethodWithResult"}

{"type":"data","data":"SOMETHING COOL"}
I wish to send something like the above json using what i think is correct from the b4j_ws.js script which are raiseEvent and ws.send is this the correct way?
 
Last edited:

monic

Active Member
Licensed User
Longtime User
Hi,

I had already installed the B4J client app and server and they work successfully, I just wanted to find a pointer to do away with the textbox and button used in the demo page /push/index.html and just use jquery to send to the client.

I've looked at the B4J and the B4A app and i cant find where the textbox and button are binding to the script as when I change the textbox name it displays null as expected?
 
Last edited:
Upvote 0
Top