当前位置: 首页>>代码示例>>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;未经允许,请勿转载。