當前位置: 首頁>>代碼示例>>Python>>正文


Python Listener.close方法代碼示例

本文整理匯總了Python中listener.Listener.close方法的典型用法代碼示例。如果您正苦於以下問題:Python Listener.close方法的具體用法?Python Listener.close怎麽用?Python Listener.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在listener.Listener的用法示例。


在下文中一共展示了Listener.close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from listener import Listener [as 別名]
# 或者: from listener.Listener import close [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

示例2: int

# 需要導入模塊: from listener import Listener [as 別名]
# 或者: from listener.Listener import close [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

示例3: VpnServer

# 需要導入模塊: from listener import Listener [as 別名]
# 或者: from listener.Listener import close [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


注:本文中的listener.Listener.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。