I'm curious if it's possible to set up a WebSocket connection that allows a browser on a webpage hosted somewhere else (like a VPS or cloud server) to communicate directly with an app running on my local PC. The goal is for the web server to send commands to this app, and in turn, for the app to stream data directly back to the user's browser, while the webpage itself is served externally. I need the app for functions that don't run well in the browser.
4 Answers
Yes, it should be possible! You can use WebSockets to establish a persistent connection between your browser and a server. The browser connects to the server, and then the server can communicate with your app. When your app sends data, the server can forward that back to the browser via the WebSocket connection.
You're right about needing a backend server. Even if it's self-hosted, the server acts like a bridge between the browser and your local app. Just remember, the local app cannot create secure connections by itself since localhost certificates are tricky!
You can definitely set up a WebSocket for that! Just keep in mind that the connection is between the browser and the server, not directly to the local app. Your app will need to interact with the WebSocket connection on the server to send and receive data.
Mixing secure and unsecured connections can be an issue. If your webpage is secured, browsers will flag any unsecured connections from your local app, which could be a dealbreaker for real-time updates.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads