Android Question Which WebSocket library to use ?

wl

Well-Known Member
Licensed User
Longtime User
Hi,

If I look at https://www.b4x.com/android/forum/threads/websocket-client-library.40221/#content
I notice I would need to have some class called "WebsocketHandler" when I use the WebSocket library.

I already download the latest version but the class WebSocketHandler seems not to exist ?

B4X:
Sub btnSend_ClickDim data AsMap
data.Initialize
data.Put("message", EditText1.Text)
wsh.SendEventToServer("Device_Message", data)
End Sub

I understand I would need to to use WebSocketHandler.SendEventToServer to send a message to the server ?

Or is the link not in sync with the latest source-code of the library ?

PS: In general I find the info on websockets (B4A on client and B4J on server) scattered around multiple posts and I find it hard to get a general (up-to-date?) info.

Is there anywhere an up-to-date B4A client and corresponding B4J server that sends data in both directions ?


Thanks
 
Last edited:

wl

Well-Known Member
Licensed User
Longtime User
Ok, got it thanks through this post: https://www.b4x.com/android/forum/threads/jwebsocketclient-library.40985/#content

WebSocketHandler is a seperate class that essentially wraps the Text params (used for passing data back and forth) into Maps.

Basically, client-side you have:

B4X:
ws.SendText(jg.ToString): 'method to send data to the server: the text param should contain a map with at least an item called "event" that contains the name of method on the server (eg: Device_MessageDelivered (Data as Map))
Sub ws_TextMessage(msg As String) 'event called from the server: msg should be the json string of a map with at least a key 'prop' (name of the event) and 'value' (paramlist) (eg: prop = 'NewMessage')

server-side:

B4X:
Public Sub Device_MessageDelivered(Data As Map) 'See ws.SendText above
ws.RunFunction("NewMessage", Messages) 'See ws_TextMessage above

Correct ?

Tx
 
Upvote 0
Top