ajax长轮询tornado,数据可用时如何完成Tornado长轮询请求

我有很长的编程背景,但对Python还不熟悉,我正在研究Tornado,以构建一个长轮询服务的原型。在

我想实现的是用户连接说example.com/get/1234,这是长轮询部分。1234是用户ID。目前,它只是挂起并等待内容。然后用户使用一个新的tab/other browser/other computer/etc进入urlexample.com/set/1234?data=abcd,其中1234是用户ID,data是内容为“abcd”的变量。现在,当发生这种情况时,第一个get请求应该打印出数据“abcd”并完成请求。用户ID显然是用来允许多个用户同时使用服务的。所以简单地说:

1)转到example.com/get/1234->等待

2) 在另一个选项卡中,打开example.com/set/1234?数据=abcd

3) 在这个请求之后,第一个请求打印出abcd并完成

下面是我一直在尝试的东西,但我并没有真正推进这个,也没有找到合适的谷歌关键字来解决这个问题。在class GetHandler(tornado.web.RequestHandler):

@tornado.web.asynchronous

# Getting user ID is working

def get(self, user_id):

# This is something I'm not sure is right, but found it in an

# example. I haven't created the code_received function yet,

# nor know if it should be here? Should the code_received

# and connection finishing be called from the /set part?

cursor = self.get_argument("cursor", None)

self.wait_for_code(self.code_received, cursor=cursor)

def code_received(self, data)

self.write(data)

self.finish()

非常感谢大家的帮助。提前谢谢!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值