Web Connection
Push event from my server to client apps
Gravatar is a globally recognized avatar based on your email address. Push event from my server to client apps
  Chris Jewell
  All
  Jan 22, 2021 @ 04:52am

Hi Rick,

I've written a messaging app, where I have used WC to control the creation and management of messages. Then, each recipient PC has a small client app that periodically checks for new messages by querying the messaging server.

All is working as expected, except the server is being queried every minute by 50+ PCs and this is likely to grow, so it is quite inefficient.

Do you know of any way to get the server to push new\edited messages to the client apps?

Any advice is very welcome.

Cheers, Chris

Gravatar is a globally recognized avatar based on your email address. re: Push event from my server to client apps
  Rick Strahl
  Chris Jewell
  Jan 22, 2021 @ 02:43pm

Not directly with Web Connection, but you can use WebSockets or SignalR in .NET to send push notifications to the client side. Essentially you'd create a messaging hub in .NET (or something else than Web Connection) using SignalR or other socket technology. You can then send messages to the hub service - either using tooling like SignalR (through .NET) from FoxPro - which then pushes the message(s) out to all connected clients.

I did a session at SW Fox for this in 2017:

SWFox 2017: Real Time Applications with Web Sockets and SignalR

Note: The online sample for this is dead so the examples won't run unless you build and set up the apps locally.

The way I would do this (typical Hub and Spoke architecture):

  • Set up a SignalR or plain WebSocket Service in .NET
  • Add a REST API that can be called via HTTP (from FoxPro)
  • FoxPro app then can simply send an HTTP call to trigger push notification
  • Client side can use SignalR client or raw WebSocket code to receive messages

If you also need to capture push notifications in FoxPro, then you can use .NET to run the SignalR client in FoxPro. For Web apps the SignalR (or WebSocket) client can be handled in JavaScript.

It's doable but it's a bit of effort to set up and maintain unfortunately as there are quite a few moving pieces in all of this.

At some point I had thought about adding rudimentary socket support into Web Connection. WWWC already implements a socket server today for the Live Reload functionality and with some extra effort that could be expanded to fire a Web socket request into Web Connection. It gets tricky though because unlike plain HTTP requests, Socket requests can be async in nature and fire repeatedly, so it's trickier to handle them without overlap and threading problems (due to the single threaded vfp nature).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Push event from my server to client apps
  Chris Jewell
  Rick Strahl
  Jan 24, 2021 @ 09:29am

Thank you Rick, I will take a look 😃

© 1996-2021