當前位置: 首頁>>代碼示例>>Python>>正文


Python reactor.connectUNIXDatagram方法代碼示例

本文整理匯總了Python中twisted.internet.reactor.connectUNIXDatagram方法的典型用法代碼示例。如果您正苦於以下問題:Python reactor.connectUNIXDatagram方法的具體用法?Python reactor.connectUNIXDatagram怎麽用?Python reactor.connectUNIXDatagram使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.reactor的用法示例。


在下文中一共展示了reactor.connectUNIXDatagram方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: buildProtocol

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import connectUNIXDatagram [as 別名]
def buildProtocol(self, address):
        ws = ProducerConsumerWsProtocol()
        ws.factory = self

        control = HostapdControlProtocol(emit_json=False)
        reactor.connectUNIXDatagram(self.control_interface, control,
                bindAddress=control.bindAddress())

        ws.consumer = control
        control.consumer = ws

        ws.registerProducer(control, True)
        control.registerProducer(ws, True)

        return ws 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:17,代碼來源:hostapd_control.py

示例2: execute

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import connectUNIXDatagram [as 別名]
def execute(address, command):
    deferred = Deferred()
    consumer = SingleItemConsumer(deferred)

    protocol = HostapdControlProtocol(consumer, command=command)
    consumer.registerProducer(protocol, True)

    reactor.connectUNIXDatagram(address, protocol, bindAddress=protocol.bindAddress())
    return deferred 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:11,代碼來源:hostapd_control.py

示例3: test_exchange

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import connectUNIXDatagram [as 別名]
def test_exchange(self):
        """
        Test that a datagram can be sent to and received by a server and vice
        versa.
        """
        clientaddr = self.mktemp()
        serveraddr = self.mktemp()
        sp = ServerProto()
        cp = ClientProto()
        s = reactor.listenUNIXDatagram(serveraddr, sp)
        self.addCleanup(s.stopListening)
        c = reactor.connectUNIXDatagram(serveraddr, cp, bindAddress=clientaddr)
        self.addCleanup(c.stopListening)

        d = defer.gatherResults([sp.deferredStarted, cp.deferredStarted])
        def write(ignored):
            cp.transport.write(b"hi")
            return defer.gatherResults([sp.deferredGotWhat,
                                        cp.deferredGotBack])

        def _cbTestExchange(ignored):
            self.assertEqual(b"hi", sp.gotwhat)
            self.assertEqual(clientaddr, sp.gotfrom)
            self.assertEqual(b"hi back", cp.gotback)

        d.addCallback(write)
        d.addCallback(_cbTestExchange)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:30,代碼來源:test_unix.py

示例4: openClientMode

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import connectUNIXDatagram [as 別名]
def openClientMode(self, iface=''):
        try:
            self._lport = reactor.connectUNIXDatagram(iface, self)
        except Exception:
            raise error.CarrierError(sys.exc_info()[1])
        return self 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:8,代碼來源:unix.py

示例5: test_exchange

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import connectUNIXDatagram [as 別名]
def test_exchange(self):
        """
        Test that a datagram can be sent to and received by a server and vice
        versa.
        """
        clientaddr = self.mktemp()
        serveraddr = self.mktemp()
        sp = ServerProto()
        cp = ClientProto()
        s = reactor.listenUNIXDatagram(serveraddr, sp)
        self.addCleanup(s.stopListening)
        c = reactor.connectUNIXDatagram(serveraddr, cp, bindAddress=clientaddr)
        self.addCleanup(c.stopListening)

        d = defer.gatherResults([sp.deferredStarted, cp.deferredStarted])
        def write(ignored):
            cp.transport.write("hi")
            return defer.gatherResults([sp.deferredGotWhat,
                                        cp.deferredGotBack])

        def _cbTestExchange(ignored):
            self.failUnlessEqual("hi", sp.gotwhat)
            self.failUnlessEqual(clientaddr, sp.gotfrom)
            self.failUnlessEqual("hi back", cp.gotback)

        d.addCallback(write)
        d.addCallback(_cbTestExchange)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:30,代碼來源:test_unix.py

示例6: testExchange

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import connectUNIXDatagram [as 別名]
def testExchange(self):
        clientaddr = self.mktemp()
        serveraddr = self.mktemp()
        sp = ServerProto()
        cp = ClientProto()
        s = reactor.listenUNIXDatagram(serveraddr, sp)
        c = reactor.connectUNIXDatagram(serveraddr, cp, bindAddress = clientaddr)

        d = defer.gatherResults([sp.deferredStarted, cp.deferredStarted])
        def write(ignored):
            cp.transport.write("hi")
            return defer.gatherResults([sp.deferredGotWhat,
                                        cp.deferredGotBack])

        def cleanup(ignored):
            d1 = defer.maybeDeferred(s.stopListening)
            d1.addCallback(lambda x : os.unlink(clientaddr))
            d2 = defer.maybeDeferred(c.stopListening)
            d2.addCallback(lambda x : os.unlink(serveraddr))
            return defer.gatherResults([d1, d2])

        def _cbTestExchange(ignored):
            self.failUnlessEqual("hi", sp.gotwhat)
            self.failUnlessEqual(clientaddr, sp.gotfrom)
            self.failUnlessEqual("hi back", cp.gotback)

        d.addCallback(write)
        d.addCallback(cleanup)
        d.addCallback(_cbTestExchange)
        return d 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:32,代碼來源:test_unix.py


注:本文中的twisted.internet.reactor.connectUNIXDatagram方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。