内容表

上一话题

QIPv6Address

下一话题

QLocalSocket

QLocalServer

QLocalServer class provides a local socket based server. 更多

Inheritance diagram of PySide2.QtNetwork.QLocalServer

概要

信号

静态函数

详细描述

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

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

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

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

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

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

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

class QLocalServer ( [ parent=None ] )
param parent

QObject

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

另请参阅

listen()

PySide2.QtNetwork.QLocalServer. SocketOption

此枚举描述可用于创建套接字的可能选项。这会改变支持套接字访问权限的平台 (Linux、Windows) 访问权限。从属平台,GroupAccess 和 OtherAccess 的含义可能略有不同。

常量

描述

QLocalServer.NoOptions

无访问限定已设置。

QLocalServer.UserAccessOption

访问被限定到如创建套接字的进程的相同用户。

QLocalServer.GroupAccessOption

在 Linux 访问被限定到相同组,除创建套接字的用户外。在 Windows 访问被限定到首要进程组

QLocalServer.OtherAccessOption

在 Linux 访问可用于每个人,除创建套接字的用户和组外。在 Windows 访问可用于每个人。

QLocalServer.WorldAccessOption

无访问限定。

另请参阅

socketOptions

PySide2.QtNetwork.QLocalServer. close ( )

停止监听传入连接。现有连接不受影响,但任何新连接将被拒绝。

PySide2.QtNetwork.QLocalServer. errorString ( )
返回类型

unicode

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

另请参阅

serverError()

PySide2.QtNetwork.QLocalServer. fullServerName ( )
返回类型

unicode

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

注意:这特定于平台

PySide2.QtNetwork.QLocalServer. hasPendingConnections ( )
返回类型

bool

返回 true 若服务器有待决连接;否则返回 false .

PySide2.QtNetwork.QLocalServer. incomingConnection ( socketDescriptor )
参数

socketDescriptor quintptr

此虚拟函数被调用由 QLocalServer 当新连接可用时。 socketDescriptor is the native socket descriptor for the accepted connection.

基实现创建 QLocalSocket ,设置套接字描述符,然后存储 QLocalSocket 在待决连接的内部列表中。最后 newConnection() is emitted.

Reimplement this function to alter the server’s behavior when a connection is available.

PySide2.QtNetwork.QLocalServer. isListening ( )
返回类型

bool

返回 true 若服务器正在监听传入连接,否则 false。

PySide2.QtNetwork.QLocalServer. listen ( name )
参数

name – unicode

返回类型

bool

PySide2.QtNetwork.QLocalServer. listen ( socketDescriptor )
参数

socketDescriptor qintptr

返回类型

bool

Instructs the server to listen for incoming connections on socketDescriptor 。特性返回 false if the server is currently listening. It returns true on success; otherwise, it returns false . The socket must be ready to accept new connections with no extra platform-specific functions called. The socket is set into non-blocking mode.

serverName() , fullServerName() may return a string with a name if this option is supported by the platform; otherwise, they return an empty QString .

PySide2.QtNetwork.QLocalServer. maxPendingConnections ( )
返回类型

int

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

PySide2.QtNetwork.QLocalServer. newConnection ( )
PySide2.QtNetwork.QLocalServer. nextPendingConnection ( )
返回类型

QLocalSocket

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

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

None 被返回若在没有待决连接时调用此函数。

static PySide2.QtNetwork.QLocalServer. removeServer ( name )
参数

name – unicode

返回类型

bool

移除任何服务器实例可能导致调用 listen() to fail and returns true 若成功;否则返回 false 。此函数意味着从崩溃恢复,当先前服务器实例尚未被清理时。

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

警告

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

PySide2.QtNetwork.QLocalServer. serverError ( )
返回类型

SocketError

返回最后发生的错误类型或 NoError .

另请参阅

errorString()

PySide2.QtNetwork.QLocalServer. serverName ( )
返回类型

unicode

返回服务器名称若服务器正监听连接;否则返回 QString()

PySide2.QtNetwork.QLocalServer. setMaxPendingConnections ( numConnections )
参数

numConnections int

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

Note: Even though 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.

PySide2.QtNetwork.QLocalServer. setSocketOptions ( options )
参数

options SocketOptions

另请参阅

socketOptions()

PySide2.QtNetwork.QLocalServer. socketDescriptor ( )
返回类型

qintptr

返回服务器用于监听传入指令的本机套接字描述符,或 -1 若服务器未监听。

描述符类型从属平台:

另请参阅

listen()

PySide2.QtNetwork.QLocalServer. socketOptions ( )
返回类型

SocketOptions

返回在套接字上设置的套接字选项。

PySide2.QtNetwork.QLocalServer. waitForNewConnection ( msec )
参数

msec int

返回类型

(retval, timeOut)

等待最多 msec 毫秒或直到传入连接可用。返回 true 若连接可用;否则返回 false 。若操作超时且 timedOut 不是 None ,*timedOut 将被设为 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. is mostly useful when there is no event loop available.

非阻塞替代是连接到 newConnection() 信号。

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