应用程序设计:Scala + HTML5
我想用 Scala 和 HTML5 实现一个应用程序。我的想法是创建一个“本地”客户端-服务器架构:Scala 处理计算并生成 HTML5 作为 GUI。
在我看来,有两种可能性:
- 使用允许嵌入 HTML5 的 Java/Scala 框架。例如,SWT 有一个浏览器小部件。 JavaFX 看起来也不错。
- 使用服务器分发该程序并在本地主机上的浏览器中运行它。
需要互联网连接并忘记本地主机可能是最方便的。不幸的是,离线模式是必要的。
现在我想知道如何做到这一点:
- 第一个选项似乎更容易实现,但我想知道:如何在没有 HTTP 协议的情况下与 Javascript 进行通信?
- 第二种方法只是一个想法。你曾经做过这样的事情吗?
如果您有建议或知道一个好的框架,请继续。
更新:
我刚刚有了一个有趣的想法:我可以使用nodejs来创建类似服务器-服务器架构的东西吗?
目前,Scala 和 Coffescript 之间的通信似乎是最有问题的部分。我仍然想知道如何从应用程序的 Scala 端启动更新。 HTTP 请求是一种交换数据的好方法。遗憾的是,据我所知,“标准”Coffeescript 中没有事件挂钩来侦听服务器端 HTTP 消息。
我考虑过使用nodejs来监听服务器发送的数据。这是个好主意吗?
I'd like to implement an application with Scala and HTML5. My idea was to create a "local" client-server architecture: Scala handles the calculations and generates HTML5 as a GUI.
To my mind there are two possibilities
- Use a Java/Scala framework that allows embedded HTML5. SWT for example has a browser widget. JavaFX seems good, too.
- Distribute the program with a server and run it in a browser on localhost.
It would probably be most convenient to require an internet connection and forget about the localhost. Unfortunately an offline mode is necessary.
Now I would like to know how to get this right:
- The first option seems easier to implement but I wonder: How can I communicate with Javascript without the HTTP protocol ?
- The second approach was just an idea. Have you ever done something like this ?
If you've got advice or know a good framework please go ahead.
UPDATE :
I've just had an interesting idea: Could I use nodejs to create something like a server-server architecture ?
Right now the communication between Scala and Coffescript seems like the most problematic part. I still wonder how I could initiate an update from the Scala side of the application. A HTTP Request is a nice way to exchange data. Sadly to my knowledge in "standard" Coffeescript there would be no event hook to listen to server-side HTTP messages.
I've thought about using nodejs to listen to the server-sent data. Is this a good idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于第二个选项,您可能希望研究Play!框架或Lift。他们自动化了在 Scala 中制作 Web 应用程序所需的大量工作,包括处理 AJAX 请求。
虽然我还没有尝试打包供本地使用,但有一个更早的 关于包装 Lift 的 Stack Exchange 问题 可能相关。通过 Play 应该可以实现!以及。
With regards to the second option, you may wish to investigate the Play! Framework or Lift. They automate a lot of the work required to make a web application in Scala, including handling AJAX requests.
Although I haven't tried packaging either for local use, there was an earlier Stack Exchange question about packaging Lift which might be relevant. It should be possible with Play! as well.