听起来您要的是像 channel.enumerate_connected_clients() 这样的方法。
没有这样的。您需要使用数据存储和/或 memcache 自己跟踪它。如果您只使用数据存储,则可以执行以下操作:
定义你的模型:
class Client(db.Model):
name = db.StringProperty()
connected = db.BooleanProperty()
创建通道时创建一个新的客户端实体:
# Create an entity in the database and use its key as the clientid
client = Client(name=username, connected=False)
client.put()
token = channel.create_channel(str(client.key()))
# Then pass that token down to your client
现在在您的连接或断开处理程序中,更新“已连接”属性:
class ConnectHandler(webapp.RequestHandler):
def post(self):
client = Client.get(Key(self.request.get('from')))
client.connected = True
client.put()
# Have a similar class for DisconnectHandler,
# or be more clever by inspecting the path.
枚举您的客户实体并显示它们是留给读者的练习。正如动态更新现有客户端的列表一样。