Results 1 to 2 of 2

Thread: Working with web sockets in Lianja 5.3

  1. #1
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,771

    Working with web sockets in Lianja 5.3

    Lianja 5.3 has much improved support for web sockets in both the client and the server.

    The new “websocket” class supports both client and server functionality.

    Lets look at some sample code that echoes any message received back to the client.

    on the server.

    Code:
    proc receivedMessage(wsid, cMessage)
        Lianja.writeOutput(“received message: “+cMessage)
        if cMessage = “quit”
            clear events
        endif
        lo.sendMessage(wsid, cMessage)
    endproc 
    
    Private lo = createObject(“websocket”)
    lo.receivedMessage = receivedMessage
    lo.listen(8004)
    wait events
    in the web client...

    Code:
    var lo = Lianja.createObject(“websocket”)
    lo.receivedMessage = function(cMessage)
    {
        console.log(“Received: “ + cMessage);
    };
    lo.connect(“ws://localhost:8004”)
    lo.sendMessage(“Hello world”)
    lo.sendMessage(“quit”)
    lo.disconnect()
    Note that you can use the built-in functions json_encode() and json_encode() to pass objects back and forwards between the web client and the server.

    Hint: You can use task scheduler on windows to run your web sockets service using lianjarun which resides in c:\lianja\bin

    https://www.windowscentral.com/how-c...ler-windows-10

    or alternatively on Linux start it in a cron job.

    https://www.howtogeek.com/101288/how...crontab-files/

    Websockets can be used effectively to handle asynchronous notifications from a remote server.
    Last edited by barrymavin; 2020-05-06 at 00:28.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Location
    São Paulo - Brasil
    Posts
    27
    Hi Barry,

    Very good.

    Thank you.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us