我目前正在开发一个嵌入 Flash 游戏的项目,该项目使用 Smartfoxserver 进行 Flash 通信。这种通信主要只是同步两个玩家之间的光标和对象移动。
由于我不是 flash 爱好者,而是 ruby 程序员,所以我很好奇:flash 为这种时间敏感的数据交换提供了什么样的通信选项?我正在考虑编写一个基于 ruby-eventmachine 的通信服务器,以尽量减少对外部程序的依赖。这可行吗?
I am currently working on a project that embeds a flash game, that uses Smartfoxserver for the flash communication. That communication is mostly just synchronizing the cursor and object movements between the two players.
Since I am not a flash guy, but a ruby programmer, I got curious: What kind of communication options does flash offer for this kind of time sensitive data exchange? I was thinking of writing a ruby-eventmachine based communication server to minimize the dependencies on external programs. Would that even be feasible?
发布评论
评论(2)
虽然我没有给你一个完整的答案,因为我自己还没有完成,但我发现自己的处境与你几乎完全相同。
我当前的方法是让我的 ruby 服务器本质上只是一个处理客户端之间所有通信的套接字服务器,但是我个人打算将任何逻辑保留在服务器之外(除非我遇到改变这个想法的理由) 。
如果您还没有在 ruby 中进行过任何套接字编程,我建议您将以下内容作为跳跃点。这是有关 Ruby Socket 编程的 IBM 文档,讨论了异步数据的方法:
Ruby Sockets - IBM
我认为最终归结为性能。我目前在日常工作中使用 ruby 服务器的一个版本,但数据不必以时间敏感的方式更新。
Although I don't have a complete answer for you, because I'm not done myself, I have found myself in almost the exact same position as you.
My current approach is for my ruby server to essentially just be a socket server that handles all of the communication between clients, however I personally intend on keeping any of the logic outside of the server ( unless I run across a reason to change that idea).
If you haven't done any socket programming in ruby, I recommend the following as a jumping point. This is an IBM document on Ruby Socket programming and discusses an approach for asynchronous data:
Ruby Sockets - IBM
I think what it ultimately comes down to as well will be performance. I currently use a version of my ruby server in my daily work, but the data doesn't have to be updated in a time sensitive manner.
您可以使用(几乎?)任何支持套接字的语言创建服务器并用它来管理您的客户端。
从 Flash 的角度来看,您可以使用 ruby,但我不知道 ruby 是否适合该任务...我的意思是,您可以制作一个 PHP 套接字服务器,但它无法处理太大的压力。
SmartFoxServer 的替代方案可以是开源的 Red5,用 Java 编写。
如果您想了解 flash 内置处理 p2p 的功能:
Flash p2p:埃弗雷特教堂
在 Flash Player 10 中,adobe 添加了实时媒体 (RTMFP) 支持 - 媒体始终来自发布同行。在 Flash Player 10.1 beta 中,他们引入了组和应用程序级多播。
但是,您仍然需要服务器 (Stratus) 来处理介绍和管理活动连接。 (另外,我认为它是针对 Flash 视频的,Stratus 不支持共享对象或脚本。因此,使用 Stratus,您的应用程序将成为彼此直接通信的客户端。)
编辑:
在重新阅读你的问题和 Beanish 提供的答案后,我想我第一次弄错了你的问题。所以我只是重写了我的答案......
You can create a server in (almost?) any language that supports sockets and manage your clients with that.
From a flash perspective you could use ruby, but I don't know how fitted ruby would be for the task...I mean, you can make a PHP socket server but it would not handle much stress.
An alternative to SmartFoxServer could be open sourced Red5, written in Java.
If you want to know about flash built in capabilities in handling p2p:
Flash p2p: Everett Church
In Flash Player 10 adobe added Live media (RTMFP) support- Media was always sourced from the publishing peer. In Flash Player 10.1 beta they introduced groups and application-level multicast.
However, you would still need a server (Stratus) to handle introductions and manage active connections. ( Also, I regard it as geared towards flash video, Stratus does not support shared objects or scripting. So with Stratus, your applications will be clients communicating directly with each other.)
Edit:
After re-reading your question and the answer provided by Beanish, I think the first time I got your question wrong. So I just re-wrote my answer...