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


Python Listener.start方法代码示例

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


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

示例1: BluetoothPlugin

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
class BluetoothPlugin(ConnectionPlugin):
    ADDR_FILE = 'config/bluetooth_address'

    def __init__(self):
        super().__init__()
        self.listener = Listener()
        self.addr = self.__get_bluetooth_addr()

    # API method
    def broadcast(self, msg):
        print("BROADCASTING")
        NetworkScanner(msg).start()

    # API method
    def run(self):
        self.listener.start()

    # API method
    def address(self):
        return self.addr

    def __get_bluetooth_addr(self):
        with open(BluetoothPlugin.ADDR_FILE, 'r') as file:
            addr = file.read()

        print("Bluetooth Address: {}".format(addr))
        return addr.strip()
开发者ID:flarecast,项目名称:bluetooth,代码行数:29,代码来源:bluetooth_plugin.py

示例2: main

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
def main():
  listener = Listener()
  listener.start()
  while True:
    recv_queue_data = listener.queue.get()
    recv_data = recv_queue_data.msgtype
    distance = recv_queue_data.msg
    if recv_data == 0x05: # Follower to move forward
      totalMoves(distance)
      print ("Received Follower move forward")
    elif recv_data == 0x06: # Follower to move backward
      totalMoves(distance)
      print ("Received Follower move backward")
    elif recv_data == 0x07: # Follower to move left
      totalMoves(distance)
      print ("Received Follower move left")
    elif recv_data == 0x09: # Follower to move right
      totalMoves(distance)
      print ("Received Follower move right")
    elif recv_data == 0x13: # Follower reports found token
      followerTokenFND()
    elif recv_data == 0x15: # Scanning Follower Servo
      print ("Received Scanning Beginning")
    elif recv_data == 0x16: # Scan returned Lead Found
      scanServo()
    elif recv_data == 0x17: # Scan returned Object Found
      scanServo()
    else:
      # Something unexpected happened
      print("Received unexpected data %d" % recv_data)
  try:
    cmdInput(listener.queue)
  except KeyboardInterrupt:
    pass
  listener.close()
开发者ID:mlevy94,项目名称:ECE4534-Team1,代码行数:37,代码来源:follower_debug.py

示例3: DataGen

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
class DataGen(object):
    def __init__(self):
        conn1, conn2 = multiprocessing.Pipe()
        self.conn = conn2
        self.listener = Listener(debug_connection = conn1)
        self.listener.start()
        self.bpm_to_test = [0]
        self.bpm_energies = [0]

    def __iter__(self):
        return self
        
    def next(self):
        while self.conn.poll():
            self.bpm_to_test, self.bpm_energies = self.conn.recv()
        return (self.bpm_to_test, self.bpm_energies)
开发者ID:rdeits,项目名称:BeatTrack,代码行数:18,代码来源:wx_mpl_dynamic_graph.py

示例4: start_ip_listener

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
def start_ip_listener():
    listener_ipv4 = None
    listener_ipv6 = None

    if socket.has_ipv6:
        try:
            listener_ipv6 = Listener(shared.listening_host, shared.listening_port, family=socket.AF_INET6)
            listener_ipv6.start()
        except Exception as e:
            logging.warning('Error while starting IPv6 listener on port {}'.format(shared.listening_port))
            logging.warning(e)

    try:
        listener_ipv4 = Listener(shared.listening_host, shared.listening_port)
        listener_ipv4.start()
    except Exception as e:
        if listener_ipv6:
            logging.warning('Error while starting IPv4 listener on port {}. '.format(shared.listening_port) +
                            'However the IPv6 one seems to be working and will probably accept IPv4 connections.')
        else:
            logging.error('Error while starting IPv4 listener on port {}. '.format(shared.listening_port) +
                          'You will not receive incoming connections. Please check your port configuration')
            logging.error(e)
开发者ID:TheKysek,项目名称:MiNode,代码行数:25,代码来源:main.py

示例5: EmonHub

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
def EmonHub():
    
    # Load settings
    settings = ConfigObj("emonhub.conf", file_error=True)
    
    # Create queue for node packets
    queue = Queue.Queue(0)

    # Create and start serial listener
    a = Listener(queue,settings)
    a.start()
    
    # Create and start http dispatcher
    b = Dispatcher(queue,settings)
    b.start()

    while 1:
        try:
            time.sleep(0.1)
        except KeyboardInterrupt:
            print "Stopping threads"
            a.stop = True
            b.stop = True
            break
开发者ID:BuloZB,项目名称:development,代码行数:26,代码来源:03.py

示例6: Config

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
#! /usr/bin/env python


from config import Config # this is a subdir
from listener import Listener
from poller import Poller
import sys

if __name__ == "__main__":
    """Run the monitor. The listener class waits for requests. The
    poller class polls the PIDs that were input and forwards output
    to the output class."""
    parpid = sys.argv[1]
    cfg = Config()
    cfg.add_item('parentpid',parpid)
    lst = Listener(cfg)
    lst.start()
    print "listener started"
    # Where is the output class?
    
    pol = Poller(cfg)   
    pol.start()
    print "Poller started"
开发者ID:jjdmol,项目名称:LOFAR,代码行数:25,代码来源:monitor.py

示例7: int

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
    elif msgstring == "start":
      try:
        testcase = int(input("Select Test Case:"))
        assert testcase in range(1, 8)
      except (TypeError, AssertionError):
        print("Test case does not exist")
        continue
      listener.queue.put(InternalMessage(ROUTER, START_GAME, bytes([testcase])))

    elif msgstring == "end":
      listener.queue.put(InternalMessage(ROUTER, END_GAME, bytes([0])))

    else:
      msgstring = msgstring.encode()
      while msgstring:
        msg = InternalMessage(ROUTER, DEBUG_MSG, msgstring[:INTERNAL_MSG_SIZE + 1])
        listener.queue.put(msg)
        msgstring = msgstring[INTERNAL_MSG_SIZE + 1:]

if __name__ == "__main__":
  listener = Listener()
  outWorker = OutboundWorker(listener.queue, listener.clientList, listener.clientDict)
  listener.start()
  outWorker.start()
  try:
    cmdInput(listener)
  except KeyboardInterrupt:
    pass
  listener.close()

开发者ID:mlevy94,项目名称:ECE4534-Team1,代码行数:31,代码来源:main.py

示例8: start

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
	def start( self ):
		myConfigurationFile = ConfigurationFile( self.fileName )
		myConfiguration = myConfigurationFile.load()

		myListener = Listener( myConfiguration )
		myListener.start()
开发者ID:aldebap,项目名称:webServer,代码行数:8,代码来源:webServer.py

示例9: Main

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
class Main(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        # make variables
        self.voltage = 0
        self.current = 0

        # load gui.ui
        self.ui = loadUi('../gui/gui.ui')

        self.ui.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
        self.ui.destroyed.connect(self.shutdown)

        # show window
        self.ui.show()

        # make new log object
        self.log = Log(self.ui)

        # make new sender object
        self.sender = Sender(self.ui, self.log)

        # set events
        self.set_events()

        # initial reset
        self.sender.reset()

        # new listener
        self.listener = Listener()

        # new_data_received signal
        self.listener.data_received.connect(self.new_data_received)

        # start listener
        self.listener.start()

        # new interpreter
        self.interpreter = Interpreter(self.log, self.ui)

        # add tree
        self.add_tree()

    def add_tree(self):
        # Items for tree
        voltage_item = QTreeWidgetItem(["Spannung", str(self.voltage) + " V"])
        self.ui.treeView.addTopLevelItem(voltage_item)

        current_item = QTreeWidgetItem(["Strom", str(self.current) + " A"])
        self.ui.treeView.addTopLevelItem(current_item)

        power_item = QTreeWidgetItem(["Watt", "0 W"])
        self.ui.treeView.addTopLevelItem(power_item)

    def set_events(self):
        # sendButton clicked
        self.ui.sendButton.clicked.connect(lambda: self.sender.send("debug"))

        # holdButton clicked
        self.ui.holdButton.clicked.connect(self.log.toggle_hold)

        # clearButton clicked
        self.ui.clearButton.clicked.connect(self.log.clear_log)

        # messageInput return pressed
        self.ui.messageInput.returnPressed.connect(lambda: self.sender.send("debug"))

        # sliders value changed
        self.ui.voltageSlider.sliderReleased.connect(lambda: self.sender.send("slider-voltage"))
        self.ui.currentSlider.sliderReleased.connect(lambda: self.sender.send("slider-current"))

        # reset action
        self.ui.resetActionButton.triggered.connect(self.sender.reset)

        # automode checkbox
        self.ui.automodeCheckbox.stateChanged.connect(lambda: self.sender.send("checkbox-automode"))

        # lamp checkboxes
        self.ui.lamp1Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))
        self.ui.lamp2Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))
        self.ui.lamp3Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))
        self.ui.lamp4Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))

    def new_data_received(self, text):
        self.interpreter.interpret(text)

    def shutdown(self):
        self.listener.exit()
开发者ID:spaibs,项目名称:eCARus-IT,代码行数:91,代码来源:main.py

示例10: VpnServer

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
class VpnServer(object):

    def __init__(self, port, shared_key, connected_callback, broken_conn_callback, 
                 debug_continue, debug, app):
        self.port = port
        self.shared_key = shared_key
        self.connected_callback = connected_callback
        self.broken_conn_callback = broken_conn_callback
        self.send_queue = Queue()
        self.receive_queue = Queue()
        self.authenticated = False
        self.debug_continue = debug_continue
        self.debug = debug
        self.waiting = True
        self.sender = None
        self.receiver = None
        self.is_server = True
        self.sessionkey=''
        self.app = app

    def setup(self):
        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        except socket.error:
            return (-1, "Could not create socket")

        try:
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.socket.bind(('', self.port))
            Logger.log("Listening for connections...", self.is_server)
            self.socket.listen(1) 
        except socket.error:
            return (-1, "Could not bind socket to port " + str(self.port))

        return (0, "VPN server set to listen on port " + str(self.port))

    def send(self, msg):
        if (self.authenticated):
            Logger.log("sessionkey: " +self.sessionkey, self.is_server)
            emsg = self.auth.encrypt_message(msg, self.auth.get_sessionkey())
            self.send_queue.put(emsg)
            Logger.log("Put message on send queue: "+ msg, self.is_server)
        else:
            self.send_queue.put(msg)
            Logger.log("Put message on send queue: "+ msg, self.is_server)
    
    def receive(self):
        if not self.receive_queue.empty():
            msg = self.receive_queue.get()
            if (self.authenticated):
                msg, valid = self.auth.decrypt_message(msg, self.auth.get_sessionkey())

                if valid is False:
                    return None

                Logger.log("Decrypted msg: "+ msg, self.is_server)
            return msg
        else:
            return None

    def start(self, callback=None):
        self.listener = Listener(self.socket, self.shared_key, self, self.connected_callback, self.app)
        self.listener.start()

    def bind(self, client_socket):
        self.debug_continue.disabled = self.debug
        self.sender = Sender(client_socket, self.send_queue, self)
        self.receiver = Receiver(client_socket, self.receive_queue, self)
        self.sender.start()
        self.receiver.start()
    
    def clear_queues(self):
        self.receive_queue.queue.clear()
        self.send_queue.queue.clear()

    def broken_conn(self):
        Logger.log("Broken connection", self.is_server)
        self.send_queue.queue.clear()
        self.receive_queue.queue.clear()
        self.sender.close()
        self.receiver.close()
        self.waiting = True
        self.authenticated = False
        if (self.listener):
            self.listener.broken_conn()

    def close(self):
        Logger.log("Connection closing", self.is_server)
        self.send_queue.queue.clear()
        self.receive_queue.queue.clear()
        self.listener.close()
        self.socket.close()
        self.authenticated = False
        if self.sender:
            self.sender.close()
        if self.receiver:
            self.receiver.close()
开发者ID:EmilMaric,项目名称:CPEN442-VPN,代码行数:99,代码来源:server.py

示例11: Myclass

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
import redis
from listener import Listener

class Myclass(object):
    def __init__(self):
        pass

    def test(self, a, b, c):
        print a, b, c

    def sum(self, a, b, c):
        print a + b + c

    def dispatch(self):
        self.dispatcher = {
            'test': self.test,
            'sum': self.sum
        }

r = redis.Redis()
client = Listener(r, ['__key*__:*'], Myclass())
client.start()

开发者ID:abhishek246,项目名称:redis_triggers,代码行数:24,代码来源:example.py

示例12: NetMgr

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import start [as 别名]
class NetMgr(Mgr):
    def __init__(self, engine,localOptions):
        Mgr.__init__(self, engine)
        self.engine = engine
        self.networkingEnabled = localOptions.enableNetworking
        if self.networkingEnabled:
            self.server = localOptions.server
        else:
            self.server = False
        self.ip = localOptions.ip
        self.remainingIDs = []
        self.timeToWaitForPlayers = 10

    def initialize(self):
        pass   
    def loadLevel(self):
        if self.networkingEnabled:
            self.broadcaster = Broadcaster()
            self.listener = Listener()
            self.listener.start()
            self.broadcaster.start()
        if self.server or not self.networkingEnabled:
            self.remainingIDs.append([1,""])
            self.remainingIDs.append([2,""])
    
    def releaseLevel(self):
        if self.networkingEnabled:
            self.listener.stop()
            self.broadcaster.stop()
            self.listener.join()
            self.broadcaster.join()

    def tick(self, dtime):
        if self.networkingEnabled:
            if dtime < 1 and self.timeToWaitForPlayers > 0:
                self.timeToWaitForPlayers -= dtime
            # check to see if all players are ready to start the race
            if self.timeToWaitForPlayers > 0 and self.engine.gameMgr.allPlayersReady == False:
                allReady = True
                for ent in self.engine.entMgr.entities:
                    if not ent.isReady:
                        allReady = False
                if len(self.engine.entMgr.entities) > 1:
                    self.engine.gameMgr.allPlayersReady = allReady
            elif self.timeToWaitForPlayers <= 0:
                self.engine.gameMgr.allPlayersReady = True

            # get messages
            incoming = self.listener.getMessages()
            outgoingMsgs = []
            for msgs in incoming:
                msgType, msg = messages.unpack(msgs)
                if msgType == const.STATUS:
                    found = False
                    # check to see if the status message is regarding a ship that is already created
                    for ent in self.engine.entMgr.entities:
                        if ent.shipId == msg.shipId:
                            found = True
                    # if it is, send updates to entity
                    if found and msg.shipId != self.engine.entMgr.playerIndex:
                        self.engine.entMgr.entities[msg.shipId].updateQueue.append(msg)
                    # if it isn't, create that entity
                    elif not found:
                        ent = Spaceship("Ship" + str(msg.shipId),msg.shipId, self.engine,const.MESHES[msg.shipId])
                        ent.pos = self.engine.entMgr.nextPos
                        self.engine.entMgr.nextPos.x += 40
                        self.engine.entMgr.entities.append(ent)
                # only process requests before game has started
                elif msgType == const.REQUEST and self.timeToWaitForPlayers > 0:
                    for ID in self.remainingIDs:
                        # if the id has not been issued already, or if the ID corresponds to a user who has been given an ID (but did not recieve their ID), send the ID
                        if ID[1] == "" or ID[1] ==  msg.userName:
                            outgoingMsgs.append(messages.pack(messages.InfoMessage(msg.userName,ID[0]),const.INFO))
                            ID[1] = msg.userName
                # only process info messages when this player has not been handed a playerIndex
                elif msgType == const.INFO and not self.server and self.engine.entMgr.playerIndex == -1:
                    self.engine.entMgr.playerIndex = msg.shipId
                    found = False
                    for ent in self.engine.entMgr.entities:
                        if ent.shipId == msg.shipId:
                            found = True
                    if not found:
                        ent = Spaceship("Ship" + str(msg.shipId),msg.shipId, self.engine,const.MESHES[msg.shipId])
                        ent.pos = self.engine.entMgr.nextPos
                        self.engine.entMgr.nextPos.x += 40
                        self.engine.entMgr.entities.append(ent)

            # if this player has not been handed a playerIndex, request one.
            if self.engine.entMgr.playerIndex == -1:
                outgoingMsgs.append(messages.pack(messages.RequestMessage(str(socket.gethostname())),const.REQUEST))
            # if the player has been handed a playerIndex, send the status of your ship
            else:
                myId = self.engine.entMgr.playerIndex
                myEnt = self.engine.entMgr.entities[myId]
                outgoingMsgs.append(messages.pack(messages.StatusMessage(myId,myEnt.pos,myEnt.dir,myEnt.colVel,myEnt.speed,myEnt.pitch, myEnt.roll,myEnt.isReady),const.STATUS))
            # send outgoing messages
            for msg in outgoingMsgs:
                self.broadcaster.addMessage(msg)
开发者ID:alexander-jones,项目名称:Saturn-Racing,代码行数:100,代码来源:netMgr.py


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