当前位置: 首页>>代码示例>>Python>>正文


Python socket.send方法代码示例

本文整理汇总了Python中socket.send方法的典型用法代码示例。如果您正苦于以下问题:Python socket.send方法的具体用法?Python socket.send怎么用?Python socket.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket的用法示例。


在下文中一共展示了socket.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_to_fd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def write_to_fd(self, data: memoryview) -> int:
        try:
            return self.socket.send(data)  # type: ignore
        except ssl.SSLError as e:
            if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                # In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
                # the socket is not writeable; we need to transform this into
                # an EWOULDBLOCK socket.error or a zero return value,
                # either of which will be recognized by the caller of this
                # method. Prior to Python 3.5, an unwriteable socket would
                # simply return 0 bytes written.
                return 0
            raise
        finally:
            # Avoid keeping to data, which can be a memoryview.
            # See https://github.com/tornadoweb/tornado/pull/2008
            del data 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:iostream.py

示例2: send

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def send(self, data):
        """
        Send data via TCP service.

        :param data: data
        :type data: str
        """
        try:
            self.socket.send(data)
            # TODO: rework logging to have LogRecord with extra=direction
            # TODO: separate data sent/received from other log records ?
            self._debug('> {}'.format(data))
        except socket.error as serr:
            if (serr.errno == 10054) or (serr.errno == 10053):
                self._close_ignoring_exceptions()
                info = "{} during send msg '{}'".format(serr.errno, data)
                raise RemoteEndpointDisconnected('Socket error: ' + info)
            else:
                raise 
开发者ID:nokia,项目名称:moler,代码行数:21,代码来源:tcp.py

示例3: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def __init__(self, port, data, exit_event, quiet=False):
        """
        :param port: Destination port.
        :param data: The data intend to be send in a loop.
        :param exit_event: Exit event.
        :param quiet: If true don't raise event when crash.
        """
        Thread.__init__(self)
        self.port = port
        # FIXME: socket.send(data>>127998) without read blocks thread
        if len(data) > 102400:
            data = data[0:102400]
            logging.error("Data is too long, using only first %d bytes",
                          len(data))
        self.data = data
        self.exitevent = exit_event
        self.idx = 0
        self.quiet = quiet
        self.ret_code = 1    # sets to 0 when finish properly 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:21,代码来源:qemu_virtio_port.py

示例4: run

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def run(self):
        _ClientHandler.log_info("csocketsendThread(); socket.send thread start")
        self._tx=None
        while self.__threadrun==True:
            try:
                # get queue-value in blocking mode
                self._tx=self._queue.get(True)
                self._queue.task_done()
            except:
                self.__threadrun=False
                _ClientHandler.log_critical("csocketsendThread();Error on queue.get()")
                raise

            try:
                self._request.sendall(bytes(self._tx))
            except:
                self.__threadrun=False
                _ClientHandler.log_critical("csocketsendThread();Error on socket.send")
                raise

        _ClientHandler.log_info("csocketsendThread(); socket.send thread terminated") 
开发者ID:norberts1,项目名称:hometop_HT3,代码行数:23,代码来源:ht_proxy_if.py

示例5: __waitfor_client_register

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def __waitfor_client_register(self):
        self.request.settimeout(5)
        try:
            devicetypetmp=self.request.recv(20)
            self._client_devicetype = devicetypetmp.decode('utf-8')
            _ClientHandler.log_info("Client-ID:{0}; register(); got devicetype:{1}".format(self._myownID,self._client_devicetype))
            #send client-ID to client
            sendtemp=str(self._myownID)
            self.request.sendall(sendtemp.encode("utf-8"))
        except socket.timeout:
            _ClientHandler.log_critical("Client-ID:{0}; Timeout occured, no devicetype was send".format(self._myownID))
            raise
        except socket.error as e:
            # Something else happened, handle error, exit, etc.
            _ClientHandler.log_critical("Client-ID:{0}; error '{1}' on socket.recv or socket.send".format(self._myownID, e))
            raise
        except Exception as e:
            _ClientHandler.log_critical("Client-ID:{0}; unkown error '{1}'".format(self._myownID,e))
            raise
        finally:
            self.request.settimeout(None) 
开发者ID:norberts1,项目名称:hometop_HT3,代码行数:23,代码来源:ht_proxy_if.py

示例6: write

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def write(self, data, extra={}):
        SMALL_PKT_BORDER = 0x7f
        LARGE_PKT_BORGER = 256 ** 3

        if len(data) % 4 != 0:
            print_err("BUG: MTProtoFrameStreamWriter attempted to send msg with len", len(data))
            return 0

        if extra.get("SIMPLE_ACK"):
            return self.upstream.write(data[::-1])

        len_div_four = len(data) // 4

        if len_div_four < SMALL_PKT_BORDER:
            return self.upstream.write(bytes([len_div_four]) + data)
        elif len_div_four < LARGE_PKT_BORGER:
            return self.upstream.write(b'\x7f' + int.to_bytes(len_div_four, 3, 'little') + data)
        else:
            print_err("Attempted to send too large pkt len =", len(data))
            return 0 
开发者ID:alexbers,项目名称:mtprotoproxy,代码行数:22,代码来源:mtprotoproxy.py

示例7: write_to_fd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def write_to_fd(self, data):
        return self.socket.send(data) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:iostream.py

示例8: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def __init__(self, moler_connection,
                 port, host="localhost", receive_buffer_size=64 * 4096,
                 logger=None):
        """Initialization of TCP-threaded connection."""
        super(ThreadedTcp, self).__init__(port=port, host=host,
                                          receive_buffer_size=receive_buffer_size,
                                          logger=logger)
        self.pulling_thread = None
        # make Moler happy (3 requirements) :-)
        self.moler_connection = moler_connection  # (1)
        self.moler_connection.how2send = self.send  # (2) 
开发者ID:nokia,项目名称:moler,代码行数:13,代码来源:tcp.py

示例9: testSendAfterClose

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def testSendAfterClose(self):
        # testing send() after close() with timeout
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(1)
        sock.close()
        self.assertRaises(socket.error, sock.send, "spam") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_socket.py

示例10: _testRecv

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def _testRecv(self):
        self.serv_conn.send(MSG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_socket.py

示例11: _testOverFlowRecv

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def _testOverFlowRecv(self):
        self.serv_conn.send(MSG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_socket.py

示例12: _testRecvFrom

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def _testRecvFrom(self):
        self.serv_conn.send(MSG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_socket.py

示例13: _testOverFlowRecvFrom

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def _testOverFlowRecvFrom(self):
        self.serv_conn.send(MSG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_socket.py

示例14: _testDup

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def _testDup(self):
        self.serv_conn.send(MSG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_socket.py

示例15: _testShutdown

# 需要导入模块: import socket [as 别名]
# 或者: from socket import send [as 别名]
def _testShutdown(self):
        self.serv_conn.send(MSG)
        self.serv_conn.shutdown(2) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_socket.py


注:本文中的socket.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。