Python twisted.internet.reactor.connectUNIXDatagram() Examples

The following are 7 code examples of twisted.internet.reactor.connectUNIXDatagram(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.internet.reactor , or try the search function .
Example #1
Source File: hostapd_control.py    From Paradrop with Apache License 2.0 5 votes vote down vote up
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 
Example #2
Source File: hostapd_control.py    From Paradrop with Apache License 2.0 5 votes vote down vote up
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 
Example #3
Source File: test_unix.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #4
Source File: test_unix.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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 
Example #5
Source File: unix.py    From scalyr-agent-2 with Apache License 2.0 5 votes vote down vote up
def openClientMode(self, iface=''):
        try:
            self._lport = reactor.connectUNIXDatagram(iface, self)
        except Exception:
            raise error.CarrierError(sys.exc_info()[1])
        return self 
Example #6
Source File: test_unix.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
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 
Example #7
Source File: test_unix.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
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