• PySide 模块
  • PySide.QtNetwork
  • 内容表

    上一话题

    QUdpSocket

    下一话题

    QTcpSocket

    QLocalSocket

    概要

    函数

    信号

    详细描述

    PySide.QtNetwork.QLocalSocket class provides a local socket.

    在 Windows 这是命名管道,在 Unix 这是本地域套接字。

    If an error occurs, socketError() returns the type of error, and PySide.QtCore.QIODevice.errorString() can be called to get a human readable description of what happened.

    尽管 PySide.QtNetwork.QLocalSocket is designed for use with an event loop, it's possible to use it without one. In that case, you must use PySide.QtNetwork.QLocalSocket.waitForConnected() , PySide.QtNetwork.QLocalSocket.waitForReadyRead() , PySide.QtNetwork.QLocalSocket.waitForBytesWritten() ,和 PySide.QtNetwork.QLocalSocket.waitForDisconnected() which blocks until the operation is complete or the timeout expires.

    Note that this feature is not supported on versions of Windows earlier than Windows XP.

    class PySide.QtNetwork. QLocalSocket ( [ parent=None ] )
    参数: parent PySide.QtCore.QObject

    创建新的本地套接字。 parent 自变量会被传递给 PySide.QtCore.QObject ‘s constructor.

    PySide.QtNetwork.QLocalSocket. LocalSocketState

    此枚举描述套接字可以处于的不同状态。

    常量 描述
    QLocalSocket.UnconnectedState 套接字未连接。
    QLocalSocket.ConnectingState 套接字开始建立连接。
    QLocalSocket.ConnectedState 已建立连接。
    QLocalSocket.ClosingState 套接字即将关闭 (数据可能仍在等待被写入)。
    PySide.QtNetwork.QLocalSocket. LocalSocketError

    LocalServerError 枚举表示可能发生的错误。最近错误可以被检索透过调用 QLocalSocket.error() .

    常量 描述
    QLocalSocket.ConnectionRefusedError 连接被对等方拒绝 (或超时)。
    QLocalSocket.PeerClosedError 远程套接字关闭连接。注意:客户端套接字 (即:此套接字) 将在远程关闭通知发送后被关闭。
    QLocalSocket.ServerNotFoundError 本地套接字名未找到。
    QLocalSocket.SocketAccessError 套接字操作失败,因为应用程序缺乏所需特权。
    QLocalSocket.SocketResourceError 本地系统资源不足 (如:太多套接字)。
    QLocalSocket.SocketTimeoutError 套接字操作超时。
    QLocalSocket.DatagramTooLargeError 数据报大于操作系统的限制 (可以低至 8192 字节)。
    QLocalSocket.ConnectionError 连接发生错误。
    QLocalSocket.UnsupportedSocketOperationError 本地操作系统不支持所请求的套接字操作。
    QLocalSocket.UnknownSocketError 发生无法识别的错误。
    PySide.QtNetwork.QLocalSocket. abort ( )

    中止当前连接并重置套接字。不像 PySide.QtNetwork.QLocalSocket.disconnectFromServer() , this function immediately closes the socket, clearing any pending data in the write buffer.

    另请参阅

    PySide.QtNetwork.QLocalSocket.disconnectFromServer() PySide.QtNetwork.QLocalSocket.close()

    PySide.QtNetwork.QLocalSocket. connectToServer ( name [ , openMode=QIODevice.ReadWrite ] )
    参数:
    • name – unicode
    • openMode PySide.QtCore.QIODevice.OpenMode
    PySide.QtNetwork.QLocalSocket. connected ( )
    PySide.QtNetwork.QLocalSocket. disconnectFromServer ( )

    试图关闭套接字。若有等待写入的待决数据, PySide.QtNetwork.QLocalSocket 将进入 ClosingState 并等待直到所有数据被写入。最终,它将进入 UnconnectedState 并发射 disconnectedFromServer() 信号。

    PySide.QtNetwork.QLocalSocket. disconnected ( )
    PySide.QtNetwork.QLocalSocket. error ( socketError )
    参数: socketError PySide.QtNetwork.QLocalSocket.LocalSocketError
    PySide.QtNetwork.QLocalSocket. error ( )
    返回类型: PySide.QtNetwork.QLocalSocket.LocalSocketError

    返回最后发生的错误类型。

    另请参阅

    PySide.QtNetwork.QLocalSocket.state() PySide.QtCore.QIODevice.errorString()

    PySide.QtNetwork.QLocalSocket. flush ( )
    返回类型: PySide.QtCore.bool

    This function writes as much as possible from the internal write buffer to the socket, without blocking. If any data was written, this function returns true; otherwise false is returned.

    调用此函数若需要 PySide.QtNetwork.QLocalSocket 立即开始发送缓冲数据。成功写入的字节数从属操作系统。在大多数情况下,不需调用此函数,因为 PySide.QtNetwork.QLocalSocket 将开始自动发送数据,一旦控制回到事件循环。若缺乏事件循环,调用 PySide.QtNetwork.QLocalSocket.waitForBytesWritten() 代替。

    另请参阅

    PySide.QtCore.QIODevice.write() PySide.QtNetwork.QLocalSocket.waitForBytesWritten()

    PySide.QtNetwork.QLocalSocket. fullServerName ( )
    返回类型: unicode

    返回套接字连接到的服务器路径。

    注意

    此函数的返回值是特定于平台的。

    PySide.QtNetwork.QLocalSocket. isValid ( )
    返回类型: PySide.QtCore.bool

    Returns true if the socket is valid and ready for use; otherwise returns false.

    注意

    套接字的状态必须为 ConnectedState 在读写可以发生之前。

    PySide.QtNetwork.QLocalSocket. readBufferSize ( )
    返回类型: PySide.QtCore.qint64

    返回内部读取缓冲尺寸。这限制客户端可以接收的数据量先于调用 PySide.QtCore.QIODevice.read() or PySide.QtCore.QIODevice.readAll() . A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.

    另请参阅

    PySide.QtNetwork.QLocalSocket.setReadBufferSize() PySide.QtCore.QIODevice.read()

    PySide.QtNetwork.QLocalSocket. serverName ( )
    返回类型: unicode

    返回对等方名称,指定通过 PySide.QtNetwork.QLocalSocket.connectToServer() , or an empty PySide.QtCore.QString if PySide.QtNetwork.QLocalSocket.connectToServer() has not been called or it failed.

    PySide.QtNetwork.QLocalSocket. setReadBufferSize ( size )
    参数: size PySide.QtCore.qint64

    设置尺寸为 PySide.QtNetwork.QLocalSocket ‘s internal read buffer to be size 字节。

    若缓冲尺寸被限制到某个大小, PySide.QtNetwork.QLocalSocket 不会缓冲超过此大小的数据。例外,0 缓冲尺寸意味着读取缓冲是无限的且缓冲所有传入数据。这是默认值。

    此选项是有用的若仅在某时间点读取数据 (如:在实时流应用程序中),或者,若希望保护套接字以免接收太多数据 (可能最终导致应用程序内存不足)。

    另请参阅

    PySide.QtNetwork.QLocalSocket.readBufferSize() PySide.QtCore.QIODevice.read()

    PySide.QtNetwork.QLocalSocket. state ( )
    返回类型: PySide.QtNetwork.QLocalSocket.LocalSocketState

    返回套接字的状态。

    PySide.QtNetwork.QLocalSocket. stateChanged ( socketState )
    参数: socketState PySide.QtNetwork.QLocalSocket.LocalSocketState
    PySide.QtNetwork.QLocalSocket. waitForConnected ( [ msecs=30000 ] )
    参数: msecs PySide.QtCore.int
    返回类型: PySide.QtCore.bool

    等待直到套接字被连接,最长 msecs milliseconds. If the connection has been established, this function returns true; otherwise it returns false. In the case where it returns false, you can call PySide.QtNetwork.QLocalSocket.error() to determine the cause of the error.

    以下范例最多等待 1 秒为建立连接:

    socket.connectToServer("market")
    if (socket.waitForConnected(1000))
        print("Connected!")
    										

    msecs 是 -1,此函数不会超时。

    PySide.QtNetwork.QLocalSocket. waitForDisconnected ( [ msecs=30000 ] )
    参数: msecs PySide.QtCore.int
    返回类型: PySide.QtCore.bool

    等待直到套接字已断开连接,最长 msecs milliseconds. If the connection has been disconnected, this function returns true; otherwise it returns false. In the case where it returns false, you can call PySide.QtNetwork.QLocalSocket.error() to determine the cause of the error.

    以下范例最多等待 1 秒为关闭连接:

    socket.disconnectFromServer()
    if (socket.waitForDisconnected(1000))
        print("Disconnected!")
    										

    msecs 是 -1,此函数不会超时。

    另请参阅

    PySide.QtNetwork.QLocalSocket.disconnectFromServer() PySide.QtNetwork.QLocalSocket.close()