Twisted and Websockets: Beyond Echo

前端 未结 2 973
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 12:44

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

The \"hello world\" of the websocket universe, at least at the moment, seems to be \"echo\" function

相关标签:
2条回答
  • 2021-01-11 13:05

    This is an example of an updated EchoHandler that will instead of just being reactive, be proactive.

    class ChattyHandler(WebSocketHandler):
        def connectionMade(self):
            self.transport.write('oh hai\n')
            self.saysomething()
    
        def saysomething(self):
            self.transport.write('still there?\n')
            reactor.callLater(5, self.saysomething)
    

    Unfortunately, websockets from https://github.com/rlotun/txWebSocket/ doesn't seem to have the connectionMade() method, and instead the only thing you can hook into is the __init__. usually you would just override connectionMade() if it were a 'normal' twisted protocol. --Fixed in upstream

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题