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


Python SocketServer.UDPServer类代码示例

本文整理汇总了Python中SocketServer.UDPServer的典型用法代码示例。如果您正苦于以下问题:Python UDPServer类的具体用法?Python UDPServer怎么用?Python UDPServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: server_bind

	def server_bind(self):
		if OsInterfaceIsSupported():
			try:
				self.socket.setsockopt(socket.SOL_SOCKET, 25, settings.Config.Bind_To+'\0')
			except:
				pass
		UDPServer.server_bind(self)
开发者ID:SpiderLabs,项目名称:Responder,代码行数:7,代码来源:Responder.py

示例2: server_bind

	def server_bind(self):
		MADDR = "224.0.0.252"
		self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
		self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
		Join = self.socket.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP,socket.inet_aton(MADDR) + socket.inet_aton(OURIP))

		UDPServer.server_bind(self)
开发者ID:Gajasurve,项目名称:MITMf,代码行数:7,代码来源:LLMNRpoisoner.py

示例3: __init__

    def __init__(self, HOST='localhost', PORT=4000, handler=KodemonUDPHandler, db_conn_string='sqlite:///AppData/Kodemon.sqlite'):
        #Set up the server
        UDPServer.__init__(self, (HOST, PORT), handler)

        #Set up the database connection
        engine = create_engine(db_conn_string)
        self.Session = sessionmaker(bind=engine)
开发者ID:bjornheidar,项目名称:veff-proj,代码行数:7,代码来源:KodemonUDPServer.py

示例4: __init__

 def __init__(self, server_address, RequestHandlerClass):
     UDPServer.__init__(self, server_address, RequestHandlerClass)
     self._shutdown_request = False
     
     # watchdog guards against the failure mode when the remote target fails 
     # to send any packets. If the watchdog reaches the high water mark, the 
     # server is terminated so as not to leave the server thread unterminated
     self.watchdog = 0.0
开发者ID:Koenma413,项目名称:sal-stack-lwip,代码行数:8,代码来源:sal_udpserver.py

示例5: __init__

 def __init__(self, ip, port, receiver_func=None, background=False, use_threading=True):
     self.ip_string = ip
     self.port = port
     self.receiver_func_callback = receiver_func
     self.background = background
     if use_threading:
         self.udpconnection = ThreadingUDPServer((self.ip_string, self.port), self.__receiver_thread)
     else:
         self.udpconnection = UDPServer((self.ip_string, self.port), self.__receiver_thread)
     self.udpconnection.allow_reuse_address = True
开发者ID:peterwyj,项目名称:WSDT,代码行数:10,代码来源:ALPSUDP.py

示例6: shutdown

    def shutdown(self):
        for timer in self._scheduled_timers:
            timer.cancel()
        
        
        for notification in self._notifications:
            handler = self.__get_multicast_handler()
            handler.send_byebye(notification)
            handler.release_response()

        
        UDPServer.shutdown(self)
开发者ID:stereohead,项目名称:pynplay,代码行数:12,代码来源:ssdpserver.py

示例7: __init__

    def __init__ (self):   
        from app import APP
        port = APP.BE.LOGGING._i_server_port

        UDPServer.__init__(self, ('127.0.0.1', port), None)
        Process.__init__ (self, None, None, "pcLOG" )        
        
        self.queue = Queue( APP.BE.LOGGING._i_queue_size )        
        self.backend = LoggingBackend (self.queue)
        self.backend.start()
        self.on = True
        self.start()
开发者ID:amamitzsch,项目名称:docsis-provisioning,代码行数:12,代码来源:log.py

示例8: __init__

    def __init__(self, regnancy_server_address):

        for port in xrange(12000, 25000):
            try:
                logging.info("UDPServer starts")
                UDPServer.__init__(self, ("", port), Handler)
                logging.info("UDPServer runs %i", port)
                break
            except:
                pass

        self.timeout = 0.05
        RegnancyUDPServer.regnancy_server_address = \
            regnancy_server_address
        self.running = True
开发者ID:EssEf,项目名称:Regnancy,代码行数:15,代码来源:regnancyupdserver.py

示例9: __receiver_thread

class ALPSUDPConnection:
    def __receiver_thread(self, request, client_address, server):
        message = request[0]
        if callable(self.receiver_func_callback):
            self.receiver_func_callback(self, client_address, message)
            # print client_address

    def __init__(self, ip, port, receiver_func=None, background=False, use_threading=True):
        self.ip_string = ip
        self.port = port
        self.receiver_func_callback = receiver_func
        self.background = background
        if use_threading:
            self.udpconnection = ThreadingUDPServer((self.ip_string, self.port), self.__receiver_thread)
        else:
            self.udpconnection = UDPServer((self.ip_string, self.port), self.__receiver_thread)
        self.udpconnection.allow_reuse_address = True
        # self.__objname = inspect.stack()[1][-2][0].split('=')[0].strip()

    def __serve_forever(self):
        try:
            self.udpconnection.serve_forever()
        except:
            pass

    def bind(self, thread_name="UDPConnection Thread"):
        self.udpsock_thread = ALPSThread(threadfunc=self.__serve_forever, threadname=thread_name)
        self.udpsock_thread.setDaemon(not self.background)
        self.udpsock_thread.start()

    def send(self, client_address, message, error_except=True):
        if type(client_address) is tuple:
            addr_tuple = client_address
        else:
            addr_tuple = (client_address.split(':')[0], int(client_address.split(':')[1]))

        if not error_except:
            return self.udpconnection.socket.sendto(message, addr_tuple)

        try:
            self.udpconnection.socket.sendto(message, addr_tuple)
        except Exception as e:
            ALPSDebug.alps_error(e, '\n', inspect.getframeinfo((inspect.currentframe().f_back)))
            return False
        return True

    def close(self):
        self.udpconnection.server_close()
开发者ID:peterwyj,项目名称:WSDT,代码行数:48,代码来源:ALPSUDP.py

示例10: __init__

 def __init__(self, interval):
     """
         init the DPM
         :param interval: the time interval of sending data (ms)
         :return:
     """
     self.__interval = interval / 1000.0
     self.__ip = socket.gethostbyname(socket.gethostname())
     self.__udpServer = UDPServer(('0.0.0.0', DPM_PORT), DataRecvServer)
开发者ID:edward9210,项目名称:wifi_perceive,代码行数:9,代码来源:dpm.py

示例11: __init__

    def __init__(self, args):
        """Instantiate an OSCServer.
        server_address ((host, port) tuple): the local host & UDP-port
        the server listens on
        """
        self.address_family = args.address_family

        self.args = args
        self.own_address = client_host, client_port = resolve_host(args.client_host, args.client_port, self.address_family, socket.AI_PASSIVE)
        self.chaosc_address = chaosc_host, chaosc_port = resolve_host(args.chaosc_host, args.chaosc_port, self.address_family)

        logger.info("binding to %s:%r", client_host, client_port)
        UDPServer.__init__(self, self.own_address, OSCRequestHandler)

        self.socket.setblocking(0)
        if hasattr(args, "subscribe") and args.subscribe:
            self.subscribe_me()

        self.callbacks = {}
开发者ID:DerLiveCode,项目名称:chaosc,代码行数:19,代码来源:simpleOSCServer.py

示例12: __init__

 def __init__(self, address=("239.255.255.250", 1900), handler_class=SSDPHandler):
     
     
     self._notifications = list()
     self._scheduled_timers = list()
     
     UDPServer.__init__(self, address, handler_class, bind_and_activate = False)
     
     # needed to receive multicast messages
     mreq = struct.pack("=4sl", socket.inet_aton("239.255.255.250"), socket.INADDR_ANY)
     self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)         
     self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
     self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1)
     
     
     self.notification_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     
     
     self.server_bind()
     self.server_activate()
开发者ID:stereohead,项目名称:pynplay,代码行数:21,代码来源:ssdpserver.py

示例13: test

    def test(self, selftest):
        # We need to discover SERVEP_IP and set up SERVER_PORT
        # Note: Port 7 is Echo Protocol:
        #
        # Port number rationale:
        #
        # The Echo Protocol is a service in the Internet Protocol Suite defined
        # in RFC 862. It was originally proposed for testing and measurement
        # of round-trip times[citation needed] in IP networks.
        #
        # A host may connect to a server that supports the Echo Protocol using
        # the Transmission Control Protocol (TCP) or the User Datagram Protocol
        # (UDP) on the well-known port number 7. The server sends back an
        # identical copy of the data it received.
        SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
        SERVER_PORT = 7

        # Returning none will suppress host test from printing success code
        server = UDPServer((SERVER_IP, SERVER_PORT), UDPEchoClient_Handler)
        print("HOST: Listening for UDP connections...")
        self.send_server_ip_port(selftest, SERVER_IP, SERVER_PORT)
        server.serve_forever()
开发者ID:sg-,项目名称:mbed-os,代码行数:22,代码来源:udpecho_client_auto.py

示例14: NodeReferee

class NodeReferee(object):
    
    def __init__(self, verbose=False, name="NodeReferee"):
        rospy.init_node(name, anonymous=False)
        rospy.loginfo("Stop referee by pressing CTRL + C")
        
        self.verbose = verbose
        if verbose:
            rospy.loginfo("Being verbose")
        rospy.on_shutdown(self.shutdown)

        # Publisher 
        self.topic = rospy.Publisher('soccer/referee', Bool, queue_size=10)

        # UDP Server with callback
        addr = ("", 4711)
        rospy.loginfo("listening on %s:%s" % addr)
        self.server = UDPServer(addr, Handler)
        self.server.timeout = 5
        self.server.callback = self.publish
        
        # Stoppable serve_forever workaround =)
        self.run = True
        while(self.run):
            self.server.handle_request()
        
    def publish(self, data, client_address):
        # By definition:
        # 1 => keep going / start
        # 0 => stop
        running = (data == "1")
        if self.verbose:
            rospy.loginfo("Received '%s' from %s considered as %s" % (data, client_address, str(running)))
        self.topic.publish(running)
    
    def shutdown(self):
        rospy.loginfo("Shutting down ... (can take up to %d seconds)" % self.server.timeout)
        self.run = False
开发者ID:t-knapp,项目名称:ProjTurtleBot,代码行数:38,代码来源:NodeReferee.py

示例15: setup_udp_server

    def setup_udp_server(self):
        """
        sets up a UDP server for target to connect and send test data.

        :return:
        """
        # !NOTE: There should mechanism to assert in the host test
        if self.SERVER_IP is None:
            self.log("setup_udp_server() called before determining server IP!")
            self.notify_complete(False)

        # Returning none will suppress host test from printing success code
        self.server = UDPServer((self.SERVER_IP, self.SERVER_PORT), UDPEchoClientHandler)
        ip, port = self.server.server_address
        self.SERVER_PORT = port
        self.server.allow_reuse_address = True
        self.log("HOST: Listening for UDP packets: " + self.SERVER_IP + ":" + str(self.SERVER_PORT))
        self.server_thread = Thread(target=UDPEchoClientTest.server_thread_func, args=(self,))
        self.server_thread.start()
开发者ID:AlessandroA,项目名称:mbed,代码行数:19,代码来源:udp_echo_client.py


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