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


Python socket.socket方法代碼示例

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


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

示例1: patch

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def patch(self):
        from gevent import monkey
        monkey.noisy = False

        # if the new version is used make sure to patch subprocess
        if gevent.version_info[0] == 0:
            monkey.patch_all()
        else:
            monkey.patch_all(subprocess=True)

        # monkey patch sendfile to make it none blocking
        patch_sendfile()

        # patch sockets
        sockets = []
        for s in self.sockets:
            if sys.version_info[0] == 3:
                sockets.append(socket(s.FAMILY, _socket.SOCK_STREAM,
                    fileno=s.sock.fileno()))
            else:
                sockets.append(socket(s.FAMILY, _socket.SOCK_STREAM,
                    _sock=s))
        self.sockets = sockets 
開發者ID:jpush,項目名稱:jbox,代碼行數:25,代碼來源:ggevent.py

示例2: connect

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def connect(self, server_addr):
        self._new_socket()

        logger.debug("Attempting connection to %s", str(server_addr))

        try:
            self._connect(server_addr)
        except socket.error:
            return False

        self.server_addr = server_addr
        self.recv_queue.queue.clear()

        self._reader = gevent.spawn(self._reader_loop)
        self._writer = gevent.spawn(self._writer_loop)

        logger.debug("Connected.")
        self.event_connected.set()
        return True 
開發者ID:ValvePython,項目名稱:steam,代碼行數:21,代碼來源:connection.py

示例3: disconnect

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def disconnect(self):
        if not self.event_connected.is_set():
            return
        self.event_connected.clear()

        self.server_addr = None

        if self._reader:
            self._reader.kill(block=False)
            self._reader = None
        if self._writer:
            self._writer.kill(block=False)
            self._writer = None

        self._readbuf = b''
        self.send_queue.queue.clear()
        self.recv_queue.queue.clear()
        self.recv_queue.put(StopIteration)

        self.socket.close()

        logger.debug("Disconnected.") 
開發者ID:ValvePython,項目名稱:steam,代碼行數:24,代碼來源:connection.py

示例4: __init__

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def __init__(self,
                 zmq_context,
                 zmq_proxy_xsub_url=ait.SERVER_DEFAULT_XSUB_URL,
                 zmq_proxy_xpub_url=ait.SERVER_DEFAULT_XPUB_URL,
                 **kwargs):

        if 'input' in kwargs and type(kwargs['input'][0]) is int:
            super(PortInputClient, self).__init__(zmq_context,
                                                  zmq_proxy_xsub_url,
                                                  zmq_proxy_xpub_url,
                                                  listener=int(kwargs['input'][0]))
        else:
            raise(ValueError('Input must be port in order to create PortInputClient'))

        # open sub socket
        self.sub = gevent.socket.socket(gevent.socket.AF_INET, gevent.socket.SOCK_DGRAM) 
開發者ID:NASA-AMMOS,項目名稱:AIT-Core,代碼行數:18,代碼來源:client.py

示例5: patch

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def patch(self):
        from gevent import monkey
        monkey.noisy = False

        # if the new version is used make sure to patch subprocess
        if gevent.version_info[0] == 0:
            monkey.patch_all()
        else:
            monkey.patch_all(subprocess=True)

        # monkey patch sendfile to make it none blocking
        patch_sendfile()

        # patch sockets
        sockets = []
        for s in self.sockets:
            sockets.append(socket(s.FAMILY, _socket.SOCK_STREAM,
                _sock=s))
        self.sockets = sockets 
開發者ID:chalasr,項目名稱:Flask-P2P,代碼行數:21,代碼來源:ggevent.py

示例6: green_threads

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def green_threads(self, val):
    if val and socket.socket is not gevent.socket.socket:
      warn("""
      WARNING: green_threads is set but this process is
      not monkey patched. This will cause severely degraded
      performance.
      
      CloudVolume uses gevent for cooperative (green)
      threading but it requires patching the Python standard
      library to perform asynchronous IO. Add this code to
      the top of your program (before any other imports):

        import gevent.monkey
        gevent.monkey.patch_all(threads=False)

      More Information:

      http://www.gevent.org/intro.html#monkey-patching
      """)

    self.config.green = bool(val) 
開發者ID:seung-lab,項目名稱:cloud-volume,代碼行數:23,代碼來源:precomputed.py

示例7: __init__

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def __init__(self, listener, handle=None, backlog=None, spawn='default', **ssl_args):
        BaseServer.__init__(self, listener, handle=handle, spawn=spawn)
        try:
            if ssl_args:
                ssl_args.setdefault('server_side', True)
                if 'ssl_context' in ssl_args:
                    ssl_context = ssl_args.pop('ssl_context')
                    self.wrap_socket = ssl_context.wrap_socket
                    self.ssl_args = ssl_args
                else:
                    from gevent.ssl import wrap_socket
                    self.wrap_socket = wrap_socket
                    self.ssl_args = ssl_args
            else:
                self.ssl_args = None
            if backlog is not None:
                if hasattr(self, 'socket'):
                    raise TypeError('backlog must be None when a socket instance is passed')
                self.backlog = backlog
        except:
            self.close()
            raise 
開發者ID:priyankark,項目名稱:PhonePi_SampleServer,代碼行數:24,代碼來源:server.py

示例8: _udp_socket

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def _udp_socket(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
    # backlog argument for compat with tcp_listener
    # pylint:disable=unused-argument

    # we want gevent.socket.socket here
    sock = socket(family=family, type=_socket.SOCK_DGRAM)
    if reuse_addr is not None:
        sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
    try:
        sock.bind(address)
    except _socket.error as ex:
        strerror = getattr(ex, 'strerror', None)
        if strerror is not None:
            ex.strerror = strerror + ': ' + repr(address)
        raise
    return sock 
開發者ID:priyankark,項目名稱:PhonePi_SampleServer,代碼行數:18,代碼來源:server.py

示例9: run

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def run(self):
        while True:
            for socksProxy in self.config['socksProxies']:
                s = socket.socket()
                s.settimeout(self.config['checkTimeout'])
                try:
                    socksProxy.connect(s, ('www.google.com', 80))
                    s.send(bytearray(b'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n'))
                    data = s.recv(65536)
                    if data == b'' or data == '' or data == None:
                        raise Exception()
                    socksProxy.fail = False
                    self.config['logger'].debug('Proxy %s is alive.', (socksProxy.host, socksProxy.port))
                except Exception:
                    socksProxy.failCount += 1
                    socksProxy.fail = True
                    self.config['logger'].debug('Proxy %s is dead.', (socksProxy.host, socksProxy.port))
                finally:
                    s.close()
            time.sleep(self.config['checkInterval']) 
開發者ID:lehui99,項目名稱:gipt,代碼行數:22,代碼來源:gipt.py

示例10: cleanup

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def cleanup(self):
        super(TCPConnection, self).cleanup()

        self.write_buffer = []
        self.read_buffer = ''
        if self.socket:
            self.socket.close()
            self.socket = None
        if self.net_read:
            self.net_read.kill()
            self.net_read = None
        if self.net_write:
            self.net_write.kill()
            self.net_write = None

        if not self.connected:
            return

        self.client.handle_disconnected(self.user_abort) 
開發者ID:adamb70,項目名稱:CSGO-Market-Float-Finder,代碼行數:21,代碼來源:connection.py

示例11: is_port_open

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def is_port_open(host, port):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(3.0)
        if s.connect_ex((host, int(port))) == 0:
            return True
        else:
            return False
    except Exception as e:
        return False
    finally:
        try:
            s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
            s.close()
        except Exception as e:
            pass 
開發者ID:lijiejie,項目名稱:BBScan,代碼行數:18,代碼來源:common.py

示例12: run

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def run(self):
        gevent.getcurrent().name = self.task_name
        while True:
            msg = self.outgoing_queue.get()
            if not isinstance(msg, PeerDisconnectedMessage):
                try:
                    msg_bytes = self.encode(msg)
                    self.send(msg_bytes)
                except (ConnectionResetError, ConnectionAbortedError):
                    # Ignore a closed connection here. The reader will notice
                    # it and send us the DisconnectedMessage to tell us that
                    # we can close the socket and terminate
                    pass
            else:
                self.sock.close()
                if msg.exception:
                    raise msg.exception
                else:
                    break

        self.logger.info('%s(%s): writer exiting gracefully' % (self.task_name, self.task_id)) 
開發者ID:Griffon26,項目名稱:taserver,代碼行數:23,代碼來源:connectionhandler.py

示例13: client

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def client():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(('localhost', PORT))
    f = sock.makefile(mode='wr')
    f.write(MSG)
    f.flush()
    assert f.readline() == MSG
    f.close() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:10,代碼來源:serverclient.py

示例14: get_environ

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def get_environ(self):
        env = super(PyWSGIHandler, self).get_environ()
        env['gunicorn.sock'] = self.socket
        env['RAW_URI'] = self.path
        return env 
開發者ID:jpush,項目名稱:jbox,代碼行數:7,代碼來源:ggevent.py

示例15: start

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import socket [as 別名]
def start(self):
        server = socket.socket()
        server.bind((self.config['proxyHost'], self.config['proxyPort']))
        server.listen(50)
        certStore = CertificationStore(self.config)
        while True:
            try:
                client, addr = server.accept()
                Tunnel(self.config, client, certStore).start()
            except Exception:
                logging.exception('Exception in Main.start:') 
開發者ID:lehui99,項目名稱:schcp,代碼行數:13,代碼來源:scphcp.py


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