简体   繁体   中英

Add Custom Callbacks to Asyncio.Protocol Python

I wonder how i can add my own callbacks to the asyncio's class Protocol. For example here is my client class:

class EchoClientProtocol(asyncio.Protocol):
    def data_received(self, data):
        print('Data received: {!r}'.format(data.decode()))

I would like to add this callback:

def hello_received(self):
    print("Hello received")

which will be called when "Hello" is received.

Thank you for your help !

您应该解析data_received()传入数据,并在达到hello后可以像hello_received()一样调用自己的回调

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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