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


Python socket.SHUT_RDWR屬性代碼示例

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


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

示例1: listen

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def listen(server, on_read):
    sock, addr = server.accept()

    timeout = 10
    try:
        read_ready, _, _ = select.select([sock], [], [], timeout)
        while len(read_ready):
            data = sock.recv(8192)
            if on_read(sock, data):
                read_ready, _, _ = select.select([sock], [], [], 0)
            else:
                read_ready = []
    except (socket.error, select.error, OSError, ValueError):
        pass
    try:
        sock.shutdown(socket.SHUT_RDWR)
    except (socket.error, OSError, ValueError):
        pass
    sock.close() 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:21,代碼來源:_socket_server.py

示例2: proxy

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def proxy(src, dst, callback=None):
    timeout = 10
    try:
        read_ready, _, _ = select.select([src], [], [], timeout)
        while len(read_ready):
            if callback:
                callback(src, dst)
            else:
                dst.send(src.recv(8192))
            read_ready, _, _ = select.select([src], [], [], timeout)
    except (socket.error, select.error, OSError, ValueError):
        pass
    try:
        src.shutdown(socket.SHUT_RDWR)
    except (socket.error, OSError, ValueError):
        pass
    src.close()
    try:
        dst.shutdown(socket.SHUT_RDWR)
    except (socket.error, OSError, ValueError):
        pass
    dst.close() 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:24,代碼來源:_socket_proxy.py

示例3: closeConnections

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def closeConnections(self):
        try:
            self.workerSocket.shutdown(socket.SHUT_RDWR)
        except:
            pass
        try:
            self.workerSocket.close()
        except:
            pass
        try:
            self.clientSocket.shutdown(socket.SHUT_RDWR)
        except:
            pass
        try:
            self.clientSocket.close()
        except:
            pass
        signal.signal(signal.SIGTERM, signal.SIG_DFL) 
開發者ID:kata198,項目名稱:PumpkinLB,代碼行數:20,代碼來源:worker.py

示例4: connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def connect(self):
            "Connect to a host on a given (SSL) port."

            sock = socket_create_connection((self.host, self.port),
                                            self.timeout, self.source_address)

            if self._tunnel_host:
                self.sock = sock
                self._tunnel()

            server_hostname = self.host if ssl.HAS_SNI else None
            self.sock = self._context.wrap_socket(sock,
                                                  server_hostname=server_hostname)
            try:
                if self._check_hostname:
                    ssl.match_hostname(self.sock.getpeercert(), self.host)
            except Exception:
                self.sock.shutdown(socket.SHUT_RDWR)
                self.sock.close()
                raise 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:22,代碼來源:client.py

示例5: handle_LIST

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def handle_LIST(self, arg):
    self.request.sendall(b'150 Opening IMAGE mode data connection for LIST\r\n')
    s = self.data_s.accept()[0]
    reply = []
    f = self.get_file_by_namelist(self.cwd)
    if type(f) is not dict:
      # TODO send error
      return
    for el in f.keys():
      reply.append("-rwxrwx--- 1 root vboxsf 4114 Oct  4 21:58 %s" % el)

    reply = '\r\n'.join(reply)
    s.sendall(bytes(reply, "utf-8"))
    s.shutdown(socket.SHUT_RDWR)
    s.close()

    self.request.sendall(b'226 Transfer complete\r\n') 
開發者ID:gynvael,項目名稱:stream,代碼行數:19,代碼來源:server.py

示例6: handle_LIST

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def handle_LIST(self, arg):
    self.request.sendall(b'150 Opening IMAGE mode data connection for LIST\r\n')
    s = self.data_s.accept()[0]
    reply = []
    f = self.get_file_by_namelist(self.cwd)
    if type(f) is not dict:
      # TODO send error
      return
    for el, el_data in f.items():
      if type(el_data) is dict:
        reply.append("drwxrwx--- 1 root vboxsf 4096 Oct  4 21:58 %s" % el)
      else:
        reply.append("-rwxrwx--- 1 root vboxsf 1234 Oct  4 21:58 %s" % el)

    reply.append('')

    reply = '\r\n'.join(reply)
    s.sendall(bytes(reply, "utf-8"))
    s.shutdown(socket.SHUT_RDWR)
    s.close()

    self.request.sendall(b'226 Transfer complete\r\n') 
開發者ID:gynvael,項目名稱:stream,代碼行數:24,代碼來源:server.py

示例7: send_thread

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def send_thread(c, p, end, rth):
  start = time.time()
  while not end.is_set():
    if time.time() - start > TIMEOUT:
      print("TIMEOUT")
      sys.stdout.flush()
      break

    try:
      data = p.recv(4096)
    except socket.timeout:
      continue

    if not data:
      break

    c.sendall(data)

  end.set()

  rth.join()
  p.shutdown(socket.SHUT_RDWR)
  c.shutdown(socket.SHUT_RDWR)
  p.close()
  c.close() 
開發者ID:gynvael,項目名稱:stream,代碼行數:27,代碼來源:proxyhttp.py

示例8: connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def connect(self):
        sock = socket.create_connection(
            (self.host, self.port), getattr(self, 'source_address', None)
        )

        # Handle the socket if a (proxy) tunnel is present
        if hasattr(self, '_tunnel') and getattr(self, '_tunnel_host', None):
            self.sock = sock
            self._tunnel()

        self.sock = ssl.wrap_socket(
            sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.ca_bundle
        )
        try:
            match_hostname(self.sock.getpeercert(), self.host)
        except CertificateError:
            self.sock.shutdown(socket.SHUT_RDWR)
            self.sock.close()
            raise 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:21,代碼來源:ssl_support.py

示例9: send

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def send(self, msg):
        msg = msg.encode()
        if msg == b'dead':
            self.is_dead = True
            if self.is_connected:
                self.sock.shutdown(socket.SHUT_RDWR)
                print("shutdown socket")
            return True
        elif self.is_connected:
            try:
                self.client.sendall(msg + b'\n')
                return True
            except socket.error:
                return False
        else:
            return False 
開發者ID:Dragon2fly,項目名稱:vpngate-with-proxy,代碼行數:18,代碼來源:vpn_indicator.py

示例10: run

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def run(self):
        retry = True

        self.logger.info("Connecting to Socket")
        sel = selectors.DefaultSelector()
        conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        conn.setsockopt(
            socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
        conn.setblocking(False)

        conn.connect_ex((self.ip, self.port))
        sel.register(conn, selectors.EVENT_READ, data=None)

        while retry:
            events = sel.select()
            for key, mask in events:
                retry = self.__handle_client__(key, mask, sel)

        sel.unregister(conn)
        if self.result['success']:
            conn.shutdown(socket.SHUT_RDWR)

        self.qresult.put(self.result)
        self.logger.info("Socket Closed") 
開發者ID:kd8bny,項目名稱:LiMEaide,代碼行數:26,代碼來源:tcp_client.py

示例11: close

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def close(self):
        if self._connected:
            log.info("Disconnecting DirectTcp socket")
            # Send a shutdown to the socket so the select returns and wait until the thread is closed before actually
            # closing the socket.
            self._connected = False
            self._sock.shutdown(socket.SHUT_RDWR)
            self._t_recv.join()
            self._sock.close() 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:11,代碼來源:transport.py

示例12: close

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def close(self):
        self.should_connect = False
        self.retry = 0
        self.resp.raw._fp.fp._sock.shutdown(socket.SHUT_RDWR)
        self.resp.raw._fp.fp._sock.close() 
開發者ID:afropolymath,項目名稱:pyfirebase,代碼行數:7,代碼來源:firebase.py

示例13: Close

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def Close(self) :
        if self._wrBufView :
            try :
                self._socket.send(self._wrBufView)
            except :
                pass
        try :
            self._socket.shutdown(socket.SHUT_RDWR)
        except :
            pass
        return self._close(XClosedReason.ClosedByHost)

    # ------------------------------------------------------------------------ 
開發者ID:jczic,項目名稱:MicroWebSrv2,代碼行數:15,代碼來源:XAsyncSockets.py

示例14: shutdown

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def shutdown(self):
        if self.wthr == None:
            return
        self.wthr.shutdown()
        try:
            self.clientsock.shutdown(socket.SHUT_RDWR)
        except Exception as e:
            if not isinstance(e, socket.error) or e.errno != ENOTCONN:
                dump_exception('self.clientsock.shutdown(socket.SHUT_RDWR)')
        self.clientsock.close()
        self.wthr = None
        self.rthr = None 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:14,代碼來源:CLIManager.py

示例15: shutdown

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_RDWR [as 別名]
def shutdown(self):
        try:
            self.skt.shutdown(socket.SHUT_RDWR)
        except:
            pass
        self.wi_available.acquire()
        self.wi.append(None)
        self.wi_available.notify()
        self.wi_available.release()
        self.uopts.data_callback = None
        for worker in self.asenders + self.areceivers:
            worker.join()
        self.asenders = None
        self.areceivers = None 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:16,代碼來源:Udp_server.py


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