NetTalk Central

Author Topic: WebSockets Host/Session and Channel "watch" variables  (Read 6236 times)

de la Rosa

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • Email
WebSockets Host/Session and Channel "watch" variables
« on: July 17, 2019, 01:00:09 AM »
Hi Bruce,

How do I specify a "channel:name" in the host variable to display in a NetWebform for websocket derived variable?

Thanks,
Vic


« Last Edit: July 21, 2019, 05:35:56 PM by de la Rosa »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: WebSockets WebForm variable
« Reply #1 on: July 17, 2019, 06:26:45 AM »
Hi Vic,

A lot for information necessary before that question begins to make sense...

cheers
Bruce

de la Rosa

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • Email
Re: WebSockets Host/Session and Channel "watch" variables
« Reply #2 on: July 17, 2019, 09:16:07 PM »
Hi Bruce,

In the webserver websocket example you demonstrated how to display a host variable “live”, however all users get the same value. What I need to display “live” is incoming messages specific only for the Logged-in user of the webform which as I understood it I can segregate thru channel and group combination, but how do I specify that channel/group combination in the field to display on the form? The group part should be associated with the current user/session of the webform to make it unique to the user, right? such as using the user.session ID as group perhaps?

In addition, will it be “live” only when the value is updated from a ProcessWebSocketCommand event or can I call a setValue procedure to change the channel:group value from say a WebServer page_received and still have it update “live”?

Thanks,
Vic
« Last Edit: July 21, 2019, 05:37:27 PM by de la Rosa »

de la Rosa

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • Email
Re: WebSockets Host/Session and Channel "watch" variables
« Reply #3 on: July 21, 2019, 05:33:52 PM »
Hi Bruce,

Am I correct in thinking that to "live" update a watched session value display field on a WebForm, from ProcessWebSocketCommand embed point, I need to access  the SessionDataQueue directly via p_web.RequestData.Webserver? I'm not referring to Websocket communications between the WebForm and the WebServer but from another independent WebSocket Client coming in on an independent thread.

Thanks,
Vic


Thanks,
Vic
« Last Edit: July 21, 2019, 05:53:58 PM by de la Rosa »

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: WebSockets Host/Session and Channel "watch" variables
« Reply #4 on: July 21, 2019, 06:30:46 PM »
Hello Vic,

Are your clients desktop apps or is this all in a web application?

I currently have a desktop app that watches a host value via websocket.  I send and receive a JSON string using websockets.  That JSON string, when received, goes into a group.  I then validate the data received to determine if that "message" from the websocket is intended for that one app or for all apps watching the host value.  Each app is assigned a DeviceId and that is used in the validation. This is in the ReceiveHostValue embed on the client side.  I actually don't do anything in the server itself.   

NetSocket.ReceiveHostValue PROCEDURE(String p_HostValueName,String p_Value)

! [Priority 5000]
json        JSONClass

  CODE
  ! [Priority 2500]
 
  ! Parent Call
  PARENT.ReceiveHostValue(p_HostValueName,p_Value)
  ! [Priority 7500]
    local.SendDebugString('Host Value Received')
    local.SendDebugString(clip(p_value))
    st.SetValue(p_value)
    Case clip(p_HostValueName)
              of 'devicecommands'
                  json.Start()
                  json.TagCase = jf:CaseLower !jF:CaseAsIs
                  json.RemovePrefix = true 
                  if json.Load(devicecommands, st,'devicecommands') = jf:OK
                    If clip(devicecommands.command) <> ''
                        if Upper(clip(devicecommands.command)) = 'UPDATE'
                            local.SendUdp('Update Command Received ',2000)
                            gps:laststatus = 'Updating'
                            local.SetSocketValues()
                            mystate = mystate:CheckingInternet
                        Elsif Upper(clip(devicecommands.command)) = 'RESTART'
                            local.SendUdp('Restart Command Received ',2000)
                            mystate = ''
                            ThisWindow{PROP:Timer} = 0
                            gps:laststatus = 'Restarting'
                            local.SetSocketValues()
                            gSelfService.RestartService()
                        Elsif Upper(clip(devicecommands.command)) = 'RESETGPS'
                            gps:laststatus = 'Resetting GPS'
                            local.SetSocketValues()
                            local.ColdStartGPS()
                        end
                    End 
                  End
    End

Maybe that helps.

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

de la Rosa

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • Email
Re: WebSockets Host/Session and Channel "watch" variables
« Reply #5 on: July 22, 2019, 12:11:52 AM »
Hi Don,

Thanks for the response. It's all good and straight forward on a desktop app as you can direct to specific clients. However, on a webForm, it's common to all users and so the only way I know is to have it on a session value and indeed the template setting has a choice of using a sessionvalue and updating live via websocket but then how would the webhandler's ProcessWebsocketCommand know which session's sessionvalue to update when the WebSocket is not tied to any session? So I'm thinking of updating the sessionvalue directly thru the sessiondataQueue and just wondering whether that's enough or do I still need to do p_web.PushSessionValue() after for it to update "live" on the WebForm?

Thanks,
Vic

« Last Edit: July 22, 2019, 12:13:45 AM by de la Rosa »