0

我正在尝试使用数据报和命名管道来实现一个简单的客户端。

我将协议定义如下:

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. 将 UNIX 客户端与 Twisted 一起使用的正确方法是什么?

4

1 回答 1

1

端点不适用于数据报协议。你需要使用reactor.listenUNIXDatagram(console_path, console_protocol). 确保不要混淆 UNIX 套接字和命名管道:它们是不同的、不兼容的东西。Twisted 不支持通过命名管道进行通信。

于 2013-08-09T19:56:29.533 回答