NetTalk Central

Author Topic: Communicating with a specific session's webhandler from WebServer  (Read 4076 times)

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
My requirement is to be able to ask a session's webhandler to show a message page, however I want to do this not in response to user interaction but from a separate process in the webserver application, possibly using the webserver class methods.

In effect I'd like to cause something like this to be executed:

p_web.Script(p_web.WindowOpen('MyMessagePage'))

Given I will have the specific SessionID is there any way from the WebServer class to

1. set a session value for a specific session using the SessionID, there appears to be a possible method _SetSessionValue, however I'm unsure of it's usage.
2. send the session's webhandler an event or in some other way communicate with it to cause it to execute some code.

I'm aware that the message page will only be shown if the user has the browser page open and the session is still active.

Any enlightenment gratefully received.

Gordon

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #1 on: August 11, 2021, 04:24:14 AM »
Hi Gordon,

there is no "WebHandler for a session".
There is a webHandler for each incoming request. So over time, a session will have zillions of web handlers.
And when the user is "doing nothing" (ie pretty much all the time) there is no webHandler at all for the session.

>> I want to do this not in response to user interaction but from a separate process in the webserver application,

The web is built on a request/response system. The browser makes a connection, posts a request, gets a response, and closes the connection. So you can't "push" stuff at the browser because there's no connection to push it down.  To have a connnection to the browser "open and listening for push stuff" we get into the subject of WebScokets.
https://www.capesoft.com/docs/NetTalk12/NetTalkWebBasic.htm#WebSockets

Basically a web socket is a "back door" connection between the browser and server which you can use to push data to the server, but only if the browser is on a page with a WebSocket connection.

there is built-in support for doing things like watching session values, refreshing browses and so on. More complex things can be done by writing JavaScript on the client side, but perhaps that is best discussed in a webinar.

Cheers
Bruce



GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #2 on: August 11, 2021, 05:28:02 AM »
Thank you for the explanation Bruce, I think after years of non web development I'm making assumptions that aren't applicable for web apps, it's a mindset that will take a while to change.

Also thanks for clarifying the webhandler situation, it makes total sense once explained.

I'll take a look at websockets and the information you suggest, I've a lot to learn.

Gordon
« Last Edit: August 11, 2021, 05:30:08 AM by GordonF »

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #3 on: August 11, 2021, 07:12:28 AM »
Bruce, just a quick question regarding the websocket features do they work with https?

I ask because the example websocket program is http and works fine, if I add websockets to my application and just add the simple "usersonline" example to my application footer the number is always zero, that is to say s_web.WebSocketServer.NumSocketsOpen is always zero. I have ticked the websockets option in the webserver extension scripts tab. Could it be related to certificates?

Gordon


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #4 on: August 13, 2021, 05:43:43 AM »
>>  regarding the websocket features do they work with https?

yes. HTTPS or HTTP - they match whatever the connection to the WebServer is.

>> Could it be related to certificates?

assuming the rest of the site works under HTTPS - no, it's not the certificates.

>> I have ticked the websockets option in the webserver extension scripts tab.

make sure your app is in "Development" mode (Performance tab template options) for your initial exploring.


cheers
Bruce

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #5 on: August 16, 2021, 05:47:35 AM »
Thanks for the help Bruce, the websockets example I mentioned works if I set my app to Development in the performance Tab, if set to Deployment it doesn't work until I set "Combine common files" to false.

Is this the behaviour you would expect and is that needed for all applications that enable websockets?

Gordon

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #6 on: August 16, 2021, 10:21:16 PM »
Hi Gordon,

If you change the scripts used by a program, then you need to click that GzipAll button on the tab (or just run Gzipall.bat) to rebuild the all.js and all.css files.

cheers
Bruce

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Communicating with a specific session's webhandler from WebServer
« Reply #7 on: August 17, 2021, 01:06:32 AM »
Thanks Bruce