データグラムと名前付きパイプを使用して、ねじれたシンプルなクライアントを実装しようとしています。
プロトコルを次のように定義します。
class ConsoleProtocol(protocol.DatagramProtocol):
def __init__(self, machine, console_path):
self.console_path = console_path
self.transport = None
def datagramReceived(self, datagram, addr):
self.logger.debug("datagramReceived()")
# blah, doing stuff !
def sendHalt(self):
self.logger.debug("sending message to fifo %s", self.console_path)
self.transport.write("ahaha", self.console_path)
そして、UNIX クライアント エンドポイントに接続します。
console_endpoint = endpoints.UNIXClientEndpoint(reactor, console_path)
console_protocol = ConsoleProtocol()
endpoints.connectProtocol(self.console_endpoint, self.console_protocol)
ただし、メソッドの実行中はsendHalt()
、トランスポート引数はNoneType
. Twisted で UNIX クライアントを使用する正しい方法は何ですか?