本文介绍了扭曲和Websockets:超越回声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对网络套接字的持续好奇中,我注意到一种趋势:

In my ongoing curiosity about websockets, I'm noticing a trend:

至少在目前,websocket宇宙的"hello world"似乎是"echo"功能.也就是说,演示的应用程序通常是我发送一些东西,我收到一些东西".

The "hello world" of the websocket universe, at least at the moment, seems to be "echo" functionality. That is, the demonstrated application is typically, "I send something, I receive something."

虽然恰当地证明了该协议是可以正常工作的,但是本示例实际上仅演示了传统请求/响应周期支持的相同类型的通信.

While aptly demonstrating that the protocol is functional, this example only actually demonstrates the same type of communication that the traditional request / response cycle enables.

例如,我能找到的twisted.web.websockets的唯一演示(在服务器端)如下:

For example, the only demonstration (on the server side) that I can find of twisted.web.websockets is the following:

import sys
from twisted.python import log
from twisted.internet import reactor
from twisted.web.static import File
from twisted.web.websocket import WebSocketHandler, WebSocketSite


class Echohandler(WebSocketHandler):

    def frameReceived(self, frame):
        log.msg("Received frame '%s'" % frame)
        self.transport.write(frame + "\n")


def main():
    log.startLogging(sys.stdout)
    root = File(".")
    site = WebSocketSite(root)
    site.addHandler("/ws/echo", Echohandler)
    reactor.listenTCP(8080, site)
    reactor.run()


if __name__ == "__main__":
    main()

我该如何在这里检查推送"功能?即,如何使Web套接字保持打开状态,然后稍后在某个事件发生的时间确定,如何通过websocket发送消息,该事件的内容也受该事件影响?

How can I instead examine "push" capability here? ie, how I can leave the web socket open, and then later, at some time determined by the occurrence of some event, send a message through the websocket, the content of which is also influenced by this event?

(对此问题感兴趣的人可能也将其视为我几天前问过的令人信服的问题:)

(Those interested by this question might also regard as compelling this question that I asked a few days ago: Making moves w/ websockets and python / django ( / twisted? ))

推荐答案

使用 hendrix ,如何在在Django-NYC上的演讲中使用Websocket设置网络应用将消息从telnet服务器推送到网页.

Using hendrix, I showed how to set up a web app in a talk at Django-NYC that uses websockets to push messages from a telnet server to a web page.

这篇关于扭曲和Websockets:超越回声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:55