Android Question Which WebSocket library to use ?

Discussion in 'Android Questions' started by wl, Jan 26, 2015.

  1. wl

    wl Well-Known Member Licensed User

    Hi,

    If I look at http://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 ?

    Code:
    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: Jan 26, 2015
  2. wl

    wl Well-Known Member Licensed User

    Ok, got it thanks through this post: http://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:

    Code:
    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:

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

    Tx
     
  3. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice