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

    上一话题

    QTcpServer

    下一话题

    QSslCertificate

    QLocalServer

    详细描述

    PySide.QtNetwork.QLocalServer class provides a local socket based server.

    此类使接受传入本地套接字连接成为可能。

    调用 PySide.QtNetwork.QLocalServer.listen() to have the server start listening for incoming connections on a specified key. The PySide.QtNetwork.QLocalServer.newConnection() signal is then emitted each time a client connects to the server.

    调用 PySide.QtNetwork.QLocalServer.nextPendingConnection() to accept the pending connection as a connected PySide.QtNetwork.QLocalSocket 。函数返回的指针指向 PySide.QtNetwork.QLocalSocket 可用于与客户端通信。

    若发生错误, PySide.QtNetwork.QLocalServer.serverError() returns the type of error, and PySide.QtNetwork.QLocalServer.errorString() can be called to get a human readable description of what happened.

    当监听连接时,可获得服务器正监听的名称透过 PySide.QtNetwork.QLocalServer.serverName() .

    调用 PySide.QtNetwork.QLocalServer.close() makes PySide.QtNetwork.QLocalServer stop listening for incoming connections.

    尽管 PySide.QtNetwork.QLocalServer is designed for use with an event loop, it's possible to use it without one. In that case, you must use PySide.QtNetwork.QLocalServer.waitForNewConnection() , which blocks until either a connection is available or a timeout expires.

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

    创建新的本地套接字服务器,采用给定 parent .

    PySide.QtNetwork.QLocalServer. close ( )

    Stop listening for incoming connections. Existing connections are not effected, but any new connections will be refused.

    PySide.QtNetwork.QLocalServer. errorString ( )
    返回类型: unicode

    返回人类可读消息适合当前报告错误通过 PySide.QtNetwork.QLocalServer.serverError() . If no suitable string is available, an empty string is returned.

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

    返回服务器正监听的完整路径。

    注意:这特定于平台

    PySide.QtNetwork.QLocalServer. hasPendingConnections ( )
    返回类型: PySide.QtCore.bool

    Returns true if the server has a pending connection; otherwise returns false.

    PySide.QtNetwork.QLocalServer. isListening ( )
    返回类型: PySide.QtCore.bool

    Returns true if the server is listening for incoming connections otherwise false.

    PySide.QtNetwork.QLocalServer. listen ( name )
    参数: name – unicode
    返回类型: PySide.QtCore.bool

    告诉服务器去监听传入连接在 name 。若服务器目前正在监听,那么它会返回 false。在成功时返回 true,否则返回 false。

    name 可以是单个名称且 PySide.QtNetwork.QLocalServer 会确定正确的特定平台路径。 PySide.QtNetwork.QLocalServer.serverName() will return the name that is passed into listen.

    Usually you would just pass in a name like “foo”, but on Unix this could also be a path such as “/tmp/foo” and on Windows this could be a pipe path such as “\.pipefoo”

    Note: On Unix if the server crashes without closing listen will fail with AddressInUseError. To create a new server the file should be removed. On Windows two local servers can listen to the same pipe at the same time, but any connections will go to one of the server.

    PySide.QtNetwork.QLocalServer. maxPendingConnections ( )
    返回类型: PySide.QtCore.int

    返回最大待决已接受连接数。默认为 30。

    PySide.QtNetwork.QLocalServer. newConnection ( )
    PySide.QtNetwork.QLocalServer. nextPendingConnection ( )
    返回类型: PySide.QtNetwork.QLocalSocket

    返回下一待决连接作为已连接 PySide.QtNetwork.QLocalSocket 对象。

    套接字是作为服务器子级创建的,意味着它会被自动删除当 PySide.QtNetwork.QLocalServer 对象被销毁。当采用完成后明确删除对象仍是好主意,以避免浪费内存。

    0 is returned if this function is called when there are no pending connections.

    static PySide.QtNetwork.QLocalServer. removeServer ( name )
    参数: name – unicode
    返回类型: PySide.QtCore.bool

    移除任何服务器实例可能导致调用 PySide.QtNetwork.QLocalServer.listen() to fail and returns true if successful; otherwise returns false. This function is meant to recover from a crash, when the previous server instance has not been cleaned up.

    在 Windows,此函数什么都不做;在 Unix,它移除套接字文件给定通过 name .

    警告

    小心避免移除正运行实例的套接字。

    PySide.QtNetwork.QLocalServer. serverError ( )
    返回类型: PySide.QtNetwork.QAbstractSocket.SocketError

    Returns the type of error that occurred last or NoError.

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

    Returns the server name if the server is listening for connections; otherwise returns QString()

    PySide.QtNetwork.QLocalServer. setMaxPendingConnections ( numConnections )
    参数: numConnections PySide.QtCore.int

    把最大待决接受连接数设为 numConnections . PySide.QtNetwork.QLocalServer 将接受不超过 numConnections 传入连接先于 PySide.QtNetwork.QLocalServer.nextPendingConnection() 被调用。

    Note: Even though PySide.QtNetwork.QLocalServer will stop accepting new connections after it has reached its maximum number of pending connections, the operating system may still keep them in queue which will result in clients signaling that it is connected.

    PySide.QtNetwork.QLocalServer. waitForNewConnection ( msec )
    参数: msec PySide.QtCore.int
    返回类型: (retval, timeOut)

    等待最多 msec milliseconds or until an incoming connection is available. Returns true if a connection is available; otherwise returns false. If the operation timed out and timedOut is not 0, *timedOut will be set to true.

    This is a blocking function call. Its use is ill-advised in a single-threaded GUI application, since the whole application will stop responding until the function returns. PySide.QtNetwork.QLocalServer.waitForNewConnection() is mostly useful when there is no event loop available.

    非阻塞替代是连接到 PySide.QtNetwork.QLocalServer.newConnection() 信号。

    若 msec 为 -1,此函数不会超时。