本文整理汇总了Python中twisted.internet.reactor.listenUDP函数的典型用法代码示例。如果您正苦于以下问题:Python listenUDP函数的具体用法?Python listenUDP怎么用?Python listenUDP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listenUDP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, address = None, data_callback = None):
self.data_callback = data_callback
if address == None:
reactor.listenUDP(0, self)
else:
reactor.listenUDP(address[1], self, address[0])
filterwarnings('ignore', '^Please only pass')
示例2: _realise_connection
def _realise_connection(cls, async):
"""Return a configured statsd client connection."""
servers = config.statsd.servers
if servers is None:
raise LookupError('Unable to obtain the statsd configuration')
servers = map(None, [server.strip() for server in servers.split(";")])
if not servers:
raise LookupError('Unable to obtain the statsd configuration')
connections = []
for server in servers:
statsd_host, statsd_port = server.split(":")
statsd_port = int(statsd_port)
if async:
connection = TwistedStatsDClient.create(statsd_host,
statsd_port)
connection.disconnect_callback = \
lambda: cls._disconnect_connection(connection)
protocol = StatsDClientProtocol(connection)
from twisted.internet import reactor
reactor.listenUDP(0, protocol)
else:
connection = UdpStatsDClient(statsd_host, statsd_port)
connection.connect()
connections.append(connection)
if len(connections) == 1:
return connections[0]
return ConsistentHashingClient(connections)
示例3: nda_loop
def nda_loop():
ndutil.setTimezone()
ndlCom = NdlCom('nDroid-Executer', '127.0.0.1', 12322)
ndlCom.doCom('Initiating')
ndlCom.doCom('Loading Config')
cnfManager = CnfManager()
cnfManager.load('./nde.cnf')
cnfData = cnfManager.getCnfData()
nsQueue = Queue()
nsLock = threading.Lock()
netManager = NetManager()
netManager.setNdlCom(ndlCom)
netManager.setNsQueue(nsQueue, nsLock)
ndlCom.doCom('Starting Threads')
scheduler = Scheduler([ndlCom, nsQueue, nsLock], 'Scheduler')
scheduler.start()
reactor.listenUDP(cnfData['comPort'], netManager)
ndlCom.doCom('Listening Com Port')
reactor.run()
scheduler.join()
示例4: run_auth
def run_auth(self):
"""run auth
"""
auth_protocol = RADIUSAccess(self.config)
task.LoopingCall(auth_protocol.process_delay).start(2.7)
reactor.listenUDP(int(self.config.radiusd.auth_port), auth_protocol, interface=self.config.radiusd.host)
reactor.run()
示例5: main
def main(type):
log.startLogging(sys.stderr, setStdout=False)
if type == "1":
client_factory = client_server.Factory()
reactor.connectTCP('127.0.0.1', 8125, client_factory)
else :
client_factory = client_server.FactoryUDP()
reactor.listenUDP(0, client_factory)
def wait_for_protocol():
while len(client_factory.instances) == 0:
time.sleep(1)
return True
d = threads.deferToThread(wait_for_protocol)
def run_loop(_):
proc = CommandProcessor(client_factory.instances[0])
reactor.callInThread(proc.cmdloop)
d.addCallback(run_loop)
reactor.run()
示例6: connectionMade
def connectionMade(self):
self.sms_queue = defer.DeferredQueue()
self.sip_queue = defer.DeferredQueue()
self.sms_queue.get().addCallback(self.sipClientDataReceived)
self.sip_client_factory = SIPProxyClientProtocol(self.sms_queue, self.sip_queue)
from twisted.internet import reactor
reactor.listenUDP(5062, self.sip_client_factory)
示例7: setUpForATest
def setUpForATest(self,
ServerProtocol=TestProtocol, ClientProtocol=TestProtocol):
serverProto = ServerProtocol()
clientProto = ClientProtocol()
self.serverProto = serverProto
self.clientProto = clientProto
sf = protocol.ServerFactory()
sf.protocol = lambda: serverProto
cf = Django()
cf.protocol = lambda: clientProto
serverTransport = ptcp.PTCP(sf)
clientTransport = ptcp.PTCP(None)
self.serverTransport = serverTransport
self.clientTransport = clientTransport
serverPort = reactor.listenUDP(0, serverTransport)
clientPort = reactor.listenUDP(0, clientTransport)
self.clientPort = clientPort
self.serverPort = serverPort
return (
serverProto, clientProto,
sf, cf,
serverTransport, clientTransport,
serverPort, clientPort
)
示例8: listen
def listen(self):
# Listen on UDP port
logging.info('AgentListener: Trying to listen UDP on port %s',\
str(self.udp_port))
try:
reactor.listenUDP(self.udp_port, AgentDatagramProtocol(self))
logging.info('AgentListener: Listening UDP on port %s',\
str(self.udp_port))
except:
logging.error('AgentListener: Failed to listen UDP on port %s',\
str(self.udp_port))
# Make sure we have enabled SSL
if not self.ssl_enabled:
return
# Listen on SSL port
ssl_factory = Factory()
AgentSSLProtocol.agent_listener = self
ssl_factory.protocol = AgentSSLProtocol
ssl_context_factory = twisted.internet.ssl.DefaultOpenSSLContextFactory(\
self.key_file_name, self.cert_file_name)
logging.info('AgentListener: Trying to listen SSL on port %s',\
str(self.ssl_port))
try:
reactor.listenSSL(self.ssl_port, ssl_factory, ssl_context_factory)
logging.info('AgentListener: Listening SSL on port %s',\
str(self.ssl_port))
except:
logging.error('AgentListener: Failed to listen SSL on port %s',\
str(self.ssl_port))
示例9: main
def main():
print "AndroidProxy --- (C) Mathy Vanhoef"
print "This program comes with ABSOLUTELY NO WARRANTY."
print
print "DNS server will listen on localhost:53"
print "HTTP Proxy will listen on localhost:8007"
print
#print "Physical device: Configure your computer dns server and as router (NOT as proxy) and execute"
#print "\tiptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8007"
#print "\tiptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8007"
#print
print "Emulator: start it using: emulator @AvdName -http-proxy http://localhost:8007 -dns-server localhost"
print
print "Don't forget to start your normal proxy on localhost:8080"
print
# Setup custom DNS server
resolvers = []
resolvers.append(ProxyResolver([('8.8.8.8', 53)]))
f = server.DNSServerFactory(clients=resolvers)
p = dns.DNSDatagramProtocol(f)
reactor.listenUDP(53, p)
# Setup TCP proxy server
endpoint = TCP4ServerEndpoint(reactor, 8007)
endpoint.listen(ProxyFactory('localhost', 8080))
# Start DNS and TCP server
reactor.run();
示例10: main
def main():
reactor.listenTCP(8000, IPBusServerFactory())
reactor.listenUDP(8000, IPBusServerProtocol())
reactor.run()
reactor.stop()
示例11: main
def main():
controls_client = ControlsClient("127.0.0.1", 10301)
reactor.listenUDP(0, controls_client)
simulator_data_client = SimulatorDataClient()
reactor.listenUDP(10302, simulator_data_client)
altitude = 300.0
airspeed = 30.0
waypoints = []
with open("waypoints.csv", "r") as f:
reader = csv.reader(f, delimiter=",")
for row in reader:
waypoint = [float(row[1]), float(row[2]), altitude, airspeed]
waypoints.append(waypoint)
autopilot = Autopilot(waypoints)
autopilot_adapter = AutopilotAdapter(autopilot, controls_client)
simulator_data_client.add_simulator_data_listener(autopilot_adapter)
log_updater = task.LoopingCall(autopilot.print_log)
log_updater.start(1.0)
simulator_control = SimulatorControlClient("localhost", 8090)
simulator_control.reset()
simulator_control.resume()
reactor.run()
示例12: main
def main():
global database
global port
init()
log()
# Create connection to the Mongo DB
try:
client = MongoClient('localhost', 27017)
# Creating the database for the server
db = client[serverName]
collection = db['users']
# Access the user collection from the database
database = db.users
except:
logger.error("Cannot access the Mongo database.")
raise SystemExit
try:
reactor.listenUDP(port, mySensorUDPServer())
reactor.run(installSignalHandlers=False)
except Exception, e:
tkMessageBox.showinfo("SCPP Message", "Server All Ready Started")
# logger.info(_('Switch Shut Down'))
reactor.callFromThread(reactor.stop)
pass
示例13: send
def send(self, oscmsg):
# print "send: " + str(oscmsg)
if self.transport == None:
# bij eerste keer zenden het protocol starten
reactor.listenUDP(0, self)
# OSC bericht encoderen en versturen
self.transport.write(oscmsg.getBinary()) # no need for address
示例14: test_connect_to_other
def test_connect_to_other():
f1 = ConnectedUDPFactory(TestProtocol)
conn_proto1 = ConnectedUDPProtocol(f1, TestDatagram())
conn_proto1_addr = ("127.0.0.1", 7778)
active_proto1 = TestProtocol()
f2 = ConnectedUDPFactory(TestProtocol)
conn_proto2 = ConnectedUDPProtocol(f2, TestDatagram())
conn_proto2_addr = ("127.0.0.1", 7779)
active_proto2 = TestProtocol()
def make_connection1():
conn_proto1.connect("127.0.0.1", conn_proto2_addr[1], active_proto1)
def send_later1():
active_proto1.write_data("sent test data")
def send_much_later1():
active_proto1.write_data("sent test data much later")
def close_connection1():
active_proto1.close_connection()
def make_connection2():
conn_proto2.connect("127.0.0.1", conn_proto1_addr[1], active_proto2)
def send_later2():
active_proto2.write_data("sent test data")
def send_much_later2():
active_proto2.write_data("sent test data much later")
def close_connection2():
active_proto2.close_connection()
from twisted.internet import reactor
def stop():
reactor.stop()
reactor.listenUDP(conn_proto1_addr[1], conn_proto1)
reactor.listenUDP(conn_proto2_addr[1], conn_proto2)
reactor.callLater(1, make_connection1)
reactor.callLater(5, send_later1)
reactor.callLater(10, send_much_later1)
reactor.callLater(15, close_connection1)
reactor.callLater(20, make_connection2)
reactor.callLater(25, send_later2)
reactor.callLater(30, send_much_later2)
reactor.callLater(35, close_connection2)
reactor.callLater(40, stop)
print "prepared for run"
reactor.run()
print "stopped"
return
示例15: StartUdpServer
def StartUdpServer(context, identity=None, address=None,
defer_reactor_run=False, custom_functions=[], **kwargs):
"""
Helper method to start the Modbus Async Udp server
:param context: The server data context
:param identify: The server identity to use (default empty)
:param address: An optional (interface, port) to bind to.
:param ignore_missing_slaves: True to not send errors on a request \
to a missing slave
:param defer_reactor_run: True/False defer running reactor.run() as part \
of starting server, to be explictly started by the user
:param custom_functions: An optional list of custom function classes
supported by server instance.
"""
from twisted.internet import reactor
address = address or ("", Defaults.Port)
framer = kwargs.pop("framer", ModbusSocketFramer)
server = ModbusUdpProtocol(context, framer, identity, **kwargs)
for f in custom_functions:
server.decoder.register(f)
_logger.info("Starting Modbus UDP Server on %s:%s" % address)
reactor.listenUDP(address[1], server, interface=address[0])
if not defer_reactor_run:
reactor.run(installSignalHandlers=_is_main_thread())