如何在flex中获取服务器时间

发布于 2024-09-05 05:36:18 字数 33 浏览 2 评论 0原文

我想在我的项目中显示数字时钟,它应该显示服务器时间。

I want to display the digital clock in my project which should display the server time.

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

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

发布评论

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

评论(2

懒的傷心 2024-09-12 05:36:18

您无法通过某些 AS 类获得它,因为 flash 是在客户端计算机上执行的。您需要在服务器上有一个脚本来返回时间并调用它来同步您自己的时钟。您只能在应用程序启动时执行一次,并且还可以对发出请求和返回的时间进行计时,并从时间中减去该延迟,这样您就不会受到网络延迟的影响。

当然,您可以不时 ping 该脚本,并在需要时重新同步。

you cannot get it with some AS class because flash is executed on client's computer. you need a script on the server that returns the time and call that to sync your own clock. you can do it only once, when the app is started and you can also time the moment when you made the request and when it came back and subtract that delay from the time so you won't be affected by the network lag.

and of course, you can ping that script now and then and resync if needed.

ヤ经典坏疍 2024-09-12 05:36:18
  • 初始化后,使用 URLLoader 从服务器加载时间。服务器脚本可以传递以 UTC 表示的当前时间或自 Linux 纪元以来经过的毫秒数;如果您想考虑从服务器到 Flex 应用程序的单程行程的延迟,请在接收到的值中添加一两秒
  • 使用 Date 类读取本地时间(客户端计算机中的时间)并存储变量中服务器时间和本地时间之间的差异。
  • 使用服务器时间初始化您的数字时钟。
  • 使用每秒触发的计时器或从 enterFrame 事件处理程序更新时钟。
  • 不要在每个时钟周期中添加一秒,而是读取本地时间并将存储的差异添加到其中。这是因为 timer/enterFrame 不能保证按照指定的精确时间间隔触发 - 如果您的应用程序计算量很大,它可能会变慢。
  • Upon initialization, load the time from the server using a URLLoader. The server script can pass current time in UTC or milliseconds passed since Linux epoch; add a second or two to the received value if you want to account for the delay in one-way trip from server to the Flex app
  • Read the local time (time in client machine) using Date class and store the difference between server time and local time in a variable.
  • Initialize your digital clock with server time.
  • Update the clock using a timer that fires every second or from the enterFrame event handler.
  • Instead of adding one second in every clock tick, read the local time and add the stored difference to it. This is because timer/enterFrame is not guaranteed to fire in exact intervals as it was specified to - it might get slower if your app is computationally heavy.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文