简体   繁体   English

AppEngine网站中的在线用户

[英]Online Users in an AppEngine Website

Users can use their Google, Facebook or Twitter account to login to a site running in Google App Engine. 用户可以使用其Google,Facebook或Twitter帐户登录到Google App Engine中运行的网站。 User's session was already implemented and the three authentication providers (Google, Facebook, Twitter) already work. 用户会话已经实现,并且三个身份验证提供程序(Google,Facebook,Twitter)已经起作用。

My next task is to check if a user is online when it's profile is viewed. 我的下一个任务是查看用户的个人资料时检查用户是否在线。 How to implement this one? 如何实现这一目标? If you have some ideas, please let me know. 如果您有任何想法,请告诉我。

In addition, when a user login to the site, I saved it's email to session something like below: 另外,当用户登录该站点时,我将其电子邮件保存为会话,如下所示:

session.put("email", email);

Another thing to consider is when the user's session timed out. 要考虑的另一件事是用户的会话超时。 Can we do something if a user's session automatically timed out (not using the log-out menu/button provided in the site) by having no interaction on the site for a long period of time. 如果用户的会话在很长一段时间内没有任何交互,从而自动使会话超时(不使用站点提供的注销菜单/按钮),那么我们可以做些什么吗?

The framework used is Struts2, running in Google App Engine. 使用的框架是Struts2,可在Google App Engine中运行。

Thanks. 谢谢。

Since HTTP is request-based, not session-based, there's no way to know if a user is 'online' or not - simply put, HTTP has no concept of 'online' users. 由于HTTP是基于请求的,而不是基于会话的,因此无法知道用户是否“在线”-简单地说,HTTP没有“在线”用户的概念。

The overly complex and high overhead way to do this is to use something like the Channel API to notify you when a user leaves a page (or your site), but this is a lot of overhead for a simple feature. 完成此操作的方法过于复杂且开销很大,是在用户离开页面(或您的网站)时使用类似Channel API的方法来通知您,但这对于一个简单功能来说是很多开销。 You could also have the user's browser ping you on a regular basis when they have a page open, but again, this causes a lot of overhead and extra traffic. 当用户打开页面时,还可以让用户的浏览器定期对您执行ping操作,但这又会导致大量开销和额外流量。

A more common way is to store a record against the user in the datastore (or just in memcache, if it's not terribly significant if a user is erroneously marked as offline), recording when they last loaded a page, and update that whenever they fetch a page from your site. 一种更常见的方法是将针对用户的记录存储在数据存储区中(或者如果错误地将用户错误地标记为脱机则存储在内存缓存中,则存储在内存缓存中),记录用户上次加载页面的时间,并在每次获取页面时进行更新您网站上的页面。 Then, you show the user as 'online' if they retrieved a page within some reasonable time interval (say, half an hour), and 'offline' if not. 然后,如果用户在某个合理的时间间隔(例如半小时)内检索到页面,则将用户显示为“在线”,否则显示为“离线”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM