当前位置: 首页>>代码示例>>Python>>正文


Python internet.UDPServer方法代码示例

本文整理汇总了Python中twisted.application.internet.UDPServer方法的典型用法代码示例。如果您正苦于以下问题:Python internet.UDPServer方法的具体用法?Python internet.UDPServer怎么用?Python internet.UDPServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.application.internet的用法示例。


在下文中一共展示了internet.UDPServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_UDP

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def test_UDP(self):
        """
        Test L{internet.UDPServer} with a random port: starting the service
        should give it valid port, and stopService should free it so that we
        can start a server on the same port again.
        """
        if not interfaces.IReactorUDP(reactor, None):
            raise unittest.SkipTest("This reactor does not support UDP sockets")
        p = protocol.DatagramProtocol()
        t = internet.UDPServer(0, p)
        t.startService()
        num = t._port.getHost().port
        self.assertNotEqual(num, 0)
        def onStop(ignored):
            t = internet.UDPServer(num, p)
            t.startService()
            return t.stopService()
        return defer.maybeDeferred(t.stopService).addCallback(onStop) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_application.py

示例2: getService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def getService(self):
        """Return service to be run

        This handles the easy case where the CanaryService class is
        also the Factory/Datagram class. Subclasses should override
        this if more intricracy is needed.
        """
        if isinstance(self, Factory):
            return internet.TCPServer(self.port, self)
        elif isinstance(self, DatagramProtocol):
            return internet.UDPServer(self.port, self)

        err = 'The class %s does not inherit from either Factory or DatagramProtocol.' % (
            self.__class__.__name__
            )
        raise Exception(err) 
开发者ID:thinkst,项目名称:opencanary,代码行数:18,代码来源:__init__.py

示例3: makeService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def makeService(config):
    import client, cache, hosts

    ca, cl = [], []
    if config['cache']:
        ca.append(cache.CacheResolver(verbose=config['verbose']))
    if config['recursive']:
        cl.append(client.createResolver(resolvconf=config['resolv-conf']))
    if config['hosts-file']:
        cl.append(hosts.Resolver(file=config['hosts-file']))

    f = server.DNSServerFactory(config.zones, ca, cl, config['verbose'])
    p = dns.DNSDatagramProtocol(f)
    f.noisy = 0
    ret = service.MultiService()
    for (klass, arg) in [(internet.TCPServer, f), (internet.UDPServer, p)]:
        s = klass(config['port'], arg, interface=config['interface'])
        s.setServiceParent(ret)
    for svc in config.svcs:
        svc.setServiceParent(ret)
    return ret 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:tap.py

示例4: test_UDP

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def test_UDP(self):
        """
        Test L{internet.UDPServer} with a random port: starting the service
        should give it valid port, and stopService should free it so that we
        can start a server on the same port again.
        """
        if not interfaces.IReactorUDP(reactor, None):
            raise unittest.SkipTest("This reactor does not support UDP sockets")
        p = protocol.DatagramProtocol()
        t = internet.UDPServer(0, p)
        t.startService()
        num = t._port.getHost().port
        self.assertNotEquals(num, 0)
        def onStop(ignored):
            t = internet.UDPServer(num, p)
            t.startService()
            return t.stopService()
        return defer.maybeDeferred(t.stopService).addCallback(onStop) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_application.py

示例5: updateServers

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def updateServers(self):
        """Run a server on every interface.

        For each configured network interface this will start a TFTP
        server. If called later it will bring up servers on newly
        configured interfaces and bring down servers on deconfigured
        interfaces.
        """
        addrs_established = set(service.name for service in self.getServers())
        addrs_desired = set(get_all_interface_addresses())

        for address in addrs_desired - addrs_established:
            if not IPAddress(address).is_link_local():
                tftp_service = UDPServer(
                    self.port,
                    TransferTimeTrackingTFTP(self.backend),
                    interface=address,
                )
                tftp_service.setName(address)
                tftp_service.setServiceParent(self)

        for address in addrs_established - addrs_desired:
            tftp_service = self.getServiceNamed(address)
            tftp_service.disownServiceParent() 
开发者ID:maas,项目名称:maas,代码行数:26,代码来源:tftp.py

示例6: makeService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def makeService(config):
    ca, cl = _buildResolvers(config)

    f = server.DNSServerFactory(config.zones, ca, cl, config['verbose'])
    p = dns.DNSDatagramProtocol(f)
    f.noisy = 0
    ret = service.MultiService()
    for (klass, arg) in [(internet.TCPServer, f), (internet.UDPServer, p)]:
        s = klass(config['port'], arg, interface=config['interface'])
        s.setServiceParent(ret)
    for svc in config.svcs:
        svc.setServiceParent(ret)
    return ret 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:tap.py

示例7: getService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def getService(self):
        f = MiniSNMP()
        f.factory = self
        return internet.UDPServer(self.port, f, interface=self.listen_addr) 
开发者ID:thinkst,项目名称:opencanary,代码行数:6,代码来源:snmp.py

示例8: getService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def getService(self):
        f = MiniNtp()
        f.factory = self
        return internet.UDPServer(self.port, f, interface=self.listen_addr) 
开发者ID:thinkst,项目名称:opencanary,代码行数:6,代码来源:ntp.py

示例9: getService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def getService(self):
        f = Tftp()
        f.factory = self
        return internet.UDPServer(self.port, f, interface=self.listen_addr) 
开发者ID:thinkst,项目名称:opencanary,代码行数:6,代码来源:tftp.py

示例10: getService

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def getService(self):
        f = SIPServer()
        f.factory = self
        return internet.UDPServer(self.port, f, interface=self.listen_addr) 
开发者ID:thinkst,项目名称:opencanary,代码行数:6,代码来源:sip.py

示例11: listenUDP

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def listenUDP(self, port, proto, interface='', maxPacketSize=8192):
        s = internet.UDPServer(port, proto, interface, maxPacketSize)
        s.privileged = 1
        s.setServiceParent(self.app) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:6,代码来源:compat.py

示例12: _getPort

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def _getPort(self):
        """See :py:meth:`twisted.application.internet.UDPServer._getPort`."""
        return self._listenUDP(*self.args, **self.kwargs) 
开发者ID:maas,项目名称:maas,代码行数:5,代码来源:tftp.py

示例13: getServers

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def getServers(self):
        """Return a set of all configured servers.

        :rtype: :class:`set` of :class:`internet.UDPServer`
        """
        return {service for service in self if service is not self.refresher} 
开发者ID:maas,项目名称:maas,代码行数:8,代码来源:tftp.py

示例14: test_getPort_calls__listenUDP_with_args_from_constructor

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def test_getPort_calls__listenUDP_with_args_from_constructor(self):
        server = UDPServer(sentinel.foo, bar=sentinel.bar)
        _listenUDP = self.patch(server, "_listenUDP")
        _listenUDP.return_value = sentinel.port
        self.assertEqual(sentinel.port, server._getPort())
        self.assertThat(
            _listenUDP, MockCalledOnceWith(sentinel.foo, bar=sentinel.bar)
        ) 
开发者ID:maas,项目名称:maas,代码行数:10,代码来源:test_tftp.py

示例15: test_listenUDP_with_IPv6_address

# 需要导入模块: from twisted.application import internet [as 别名]
# 或者: from twisted.application.internet import UDPServer [as 别名]
def test_listenUDP_with_IPv6_address(self):
        server = UDPServer(0, DummyProtocol(), "::1")
        port = server._getPort()
        self.addCleanup(port.stopListening)
        self.assertEqual(AF_INET6, port.addressFamily) 
开发者ID:maas,项目名称:maas,代码行数:7,代码来源:test_tftp.py


注:本文中的twisted.application.internet.UDPServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。