如何获取实时数据?
How to get realtime data?
我正在尝试构建一个行为与此 (http://pdxlivebus.com/) 完全相同的总线应用程序。
现在我完全想不通如何从后端向 UI 不断提供数据?我不想在一段时间后发送 ajax 请求。我已经用 react 和 node.js 完成了聊天应用程序,但从某种意义上说,它们是实时的,即一个用户做某事(发送消息或断开连接),为此服务器发出一个套接字事件,客户端监听和更新。
但是像这样的应用程序 http://pdxlivebus.com/ 用户除了看公交车什么都不做 UI 如何更新最新数据?
我相信你需要集成实时数据库。
您可以使用 Firebase 数据库 https://firebase.google.com/docs/database/
这里是关于如何集成它的示例代码。
https://moquet.net/blog/realtime-geolocation-tracking-firebase/
您需要使用套接字,也许您可以使用 socket.io other great library is SuperWebSocket 与 .net 兼容并且 html5。
对于客户,我认为最好的选择是 Angularjs, is a powerful tool for work with real time data, for example this web 使用 Angularjs 显示实时数据
您可以使用 webrtc,它可以实现浏览器之间的实时通信。
或
您可以选择 socket.io,它可以实现 Web 客户端和服务器之间的实时双向通信
内部http://pdxlivebus.com/ is using socket.io – check line no. 23178 of http://pdxlivebus.com/dist/bundle.js
发出的事件vehicle_update
returns数据如:
{
"routeNumber": 100,
"delay": -37,
"inCongestion": null,
"latitude": 45.5231087,
"longitude": -122.959265,
"type": "rail",
"vehicleID": 104
}
有了这样的信息,您就可以为移动中的每个元素(vehicleID 是唯一的,很容易跟踪)制作动画。
我正在尝试构建一个行为与此 (http://pdxlivebus.com/) 完全相同的总线应用程序。
现在我完全想不通如何从后端向 UI 不断提供数据?我不想在一段时间后发送 ajax 请求。我已经用 react 和 node.js 完成了聊天应用程序,但从某种意义上说,它们是实时的,即一个用户做某事(发送消息或断开连接),为此服务器发出一个套接字事件,客户端监听和更新。
但是像这样的应用程序 http://pdxlivebus.com/ 用户除了看公交车什么都不做 UI 如何更新最新数据?
我相信你需要集成实时数据库。 您可以使用 Firebase 数据库 https://firebase.google.com/docs/database/
这里是关于如何集成它的示例代码。 https://moquet.net/blog/realtime-geolocation-tracking-firebase/
您需要使用套接字,也许您可以使用 socket.io other great library is SuperWebSocket 与 .net 兼容并且 html5。
对于客户,我认为最好的选择是 Angularjs, is a powerful tool for work with real time data, for example this web 使用 Angularjs 显示实时数据
您可以使用 webrtc,它可以实现浏览器之间的实时通信。
或
您可以选择 socket.io,它可以实现 Web 客户端和服务器之间的实时双向通信
内部http://pdxlivebus.com/ is using socket.io – check line no. 23178 of http://pdxlivebus.com/dist/bundle.js
发出的事件vehicle_update
returns数据如:
{
"routeNumber": 100,
"delay": -37,
"inCongestion": null,
"latitude": 45.5231087,
"longitude": -122.959265,
"type": "rail",
"vehicleID": 104
}
有了这样的信息,您就可以为移动中的每个元素(vehicleID 是唯一的,很容易跟踪)制作动画。