英文:
Communication between desktop application and web frontend
问题
我的项目可以分为三个组件:桌面应用程序、服务器后端和服务器前端。我正在使用WebSockets进行应用程序后端和后端前端之间的通信。前端是单页应用程序。整体看起来像这样:
我需要在前端和应用程序之间实现通信(上图中的虚线箭头)。我可以使用后端服务器作为代理,但直接在前端和应用程序之间建立直接连接会更有用,这样可以避免浪费后端资源。
有没有办法在本地应用程序和Web前端之间建立直接连接?
PS:我在后端和应用程序中使用Go语言,在前端使用JavaScript,并使用WebSockets进行通信,但欢迎提供一般架构答案。
英文:
My project can be divided into 3 components: Desktop application, Server backend, Server frontend. I am using websockets application-backend and backend-frontend communication. Frontend is single page application. Whole looks like this:
I need to implement communication between frontend and application (dotted arrow in the picture above). I am able to use backend server as a proxy, but it would be more useful to have direct communication between frontend and application so that backend resources aren't wasted.
Is there any way how I can establish direct connection between local app and web frontend?
PS: I am using Go for both backend and application, JavaScript for frontend and WebSockets for communication, but general architecture answers are welcomed.
答案1
得分: 3
你是否正在尝试从你的桌面应用程序连接到JavaScript前端?如果是的话,我可以考虑以下几种选项:
- WebRTC。它被Chrome(和Opera)和Firefox支持。
- Chrome原生消息传递,这只适用于Chrome,可以在桌面应用程序的stdin/out中发送/接收信息。
总的来说,我认为WebRTC可能是一个更好的解决方案。这两种解决方案都要求你在现代浏览器中运行你的Web前端,比如Chrome/Firefox。
如果你必须处理IE,我只能想到让你的桌面应用程序运行一个本地Web服务器,并让你的Web应用程序进行轮询/发送请求。即使这样,你仍然需要解决跨域问题,并且可能需要实现一定级别的安全性,所以会变得相当混乱。
英文:
Are you trying to connect to the JavaScript Frontend from your desktop application? If so, I can think of the following options
- WebRTC. It's supported by Chrome (and Opera) and Firefox.
- Chrome Native Messaging, this only works for chrome obviously, sends/receives info from stdin/out of your desktop application.
Overall I think WebRTC might be a better solution. Both of the solutions require you to run your web frontend in a modern browser though, Chrome/Firefox.
If you have to deal with IE, I can only think of having your desktop application to run a local web server, and have your web application poll/post to it. Even then, you have to work around cross domain issues, and you probably want to implement some level of security around it, so it gets fairly messy.
答案2
得分: 1
这可能有效,但可能需要额外的思考来确保安全:
让你的桌面程序在某个任意端口 p 上运行一个网络(socket)服务器,然后尝试从前端与 localhost:p 进行通信。
或者你可以尝试在浏览器和桌面应用程序之间使用 WebRTC。快速搜索结果显示 https://github.com/coreos/go-webrtc-datachannel,目前只是一个规划文档。
英文:
This might work, but may take quite a bit of extra thought to do securely:
Have your desktop program run a web(socket) server on some arbitrary port p, then try to talk to localhost:p from your frontend.
Or you could try to do WebRTC between the browser and desktop app. A quick search turned up https://github.com/coreos/go-webrtc-datachannel, which is just a planning document at this time.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论