Comet JSON 推送到 JavaScript

发布于 2024-12-05 01:53:56 字数 446 浏览 0 评论 0原文

我断断续续地学习 Scala 一段时间,并成功地建立并运行了一个简单的实时发布系统。

我想知道是否有人可以帮助我朝正确的方向通过 JSON 将数据更改推送到我运行的几个 javascript 模块。

基本上我正在寻找的是一个 Comet 系统,用于将 JSON 数据推送到某些页面模块,然后这些模块将接受数据并计算出如何处理它。

例如,我有一个可以在其上绘图的 html5 画布。每张绘图都以 JSON 格式临时保存,并包含形状、颜色、厚度等坐标。然后将其发送到服务器,通过 Comet 分发给房间的其他参与者。

我不太确定要搜索什么,甚至不知道从哪里开始寻找这种功能。

最好将绘图保存在数据库中,然后 Comet 拾取它并将其传递给房间中的其他人吗?

任何帮助将不胜感激,提前致谢,如果我的问题含糊不清,很抱歉,如果是这样,请告诉我,我会很乐意扩展我的解释。

干杯

I've been learning Scala for a while on and off and have successfully got a simple real time post system up and running.

I was wondering if anyone out there could help me in the right direction to pushing data changes via JSON to several javascript modules I have running.

Basically what I'm looking for is a Comet system to push JSON data down to some page modules which will then accept the data and work out what to do with it.

For example, I have an html5 canvas which can be drawn upon. Each drawing is temporarily saved in JSON format with co-ordinates of the shape, color, thickness etc. This is then sent to the server to be distributed via Comet to the rest of the room participants.

I'm not really sure what to search for or even where to start looking for this kind of functionality.

Would it be best to save the drawing in a DB and then Comet pick it up and pass it down to other people in the room?

Any help would be much appreciated, thanks in advance, and sorry if my question is vague, if so let me know and I'll happily expand on my explaination.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风无影 2024-12-12 01:53:56

在我看来,这种用例是实现 Lift 的基本用例之一,因此您可能想看一下基本的聊天示例 - http://simply.liftweb.net/index-Chapter-2.html#toc-Chapter-2

确保看看Github 上的代码链接在该页面顶部,因为书中的文本没有提供所有必要的部分。

关于您的最后一个问题,保存到数据库是您可以与处理彗星请求并行或串行执行的操作。保存到参与者内部数据库的最佳实践是将数据库访问权转移给另一个参与者,以免阻塞原始参与者的进程,但如果以后出现问题,您可以随时重构该数据库访问。

This sort of use-case strikes me as one of the base use-cases for which Lift was implemented, so you might want to give the basic Chat example a look - http://simply.liftweb.net/index-Chapter-2.html#toc-Chapter-2

Make sure to look at the code on Github linked at the top of that page, because the text in the book doesn't provide all of the necessary pieces.

Regarding your last question, saving to a database is something you can do in parallel or in series with processing the comet requests. Best practice for saving to a database inside an actor is to farm the database access out to another actor so as not to block the process of the originating actor, but you can always refactor that DB access later if it becomes a problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文