本文整理汇总了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)
示例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)
示例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
示例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)
示例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()
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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}
示例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)
)
示例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)