QLocalServerclass provides a local socket based server. 更多 …
def
close
()
def
errorString
()
def
fullServerName
()
def
isListening
()
def
listen
(name)
def
listen
(socketDescriptor)
def
maxPendingConnections
()
def
serverError
()
def
serverName
()
def
setMaxPendingConnections
(numConnections)
def
setSocketOptions
(options)
def
socketDescriptor
()
def
socketOptions
()
def
waitForNewConnection
(msec)
def
hasPendingConnections
()
def
incomingConnection
(socketDescriptor)
def
nextPendingConnection
()
def
newConnection
()
def
removeServer
(name)
此类使接受传入本地套接字连接成为可能。
调用
listen()to have the server start listening for incoming connections on a specified key. ThenewConnection()signal is then emitted each time a client connects to the server.调用
nextPendingConnection()to accept the pending connection as a connectedQLocalSocket。函数返回的指针指向QLocalSocket可用于与客户端通信。若发生错误,
serverError()returns the type of error, anderrorString()can be called to get a human readable description of what happened.当监听连接时,可获得服务器正监听的名称透过
serverName().调用
close()makesQLocalServerstop listening for incoming connections.尽管
QLocalServeris designed for use with an event loop, it’s possible to use it without one. In that case, you must usewaitForNewConnection(), which blocks until either a connection is available or a timeout expires.另请参阅
QLocalServer
(
[
parent=None
]
)
¶
- param parent
QObject
创建新的本地套接字服务器,采用给定
parent
.
另请参阅
PySide2.QtNetwork.QLocalServer.
SocketOption
¶
此枚举描述可用于创建套接字的可能选项。这会改变支持套接字访问权限的平台 (Linux、Windows) 访问权限。从属平台,GroupAccess 和 OtherAccess 的含义可能略有不同。
|
常量 |
描述 |
|---|---|
|
QLocalServer.NoOptions |
无访问限定已设置。 |
|
QLocalServer.UserAccessOption |
访问被限定到如创建套接字的进程的相同用户。 |
|
QLocalServer.GroupAccessOption |
在 Linux 访问被限定到相同组,除创建套接字的用户外。在 Windows 访问被限定到首要进程组 |
|
QLocalServer.OtherAccessOption |
在 Linux 访问可用于每个人,除创建套接字的用户和组外。在 Windows 访问可用于每个人。 |
|
QLocalServer.WorldAccessOption |
无访问限定。 |
另请参阅
PySide2.QtNetwork.QLocalServer.
close
(
)
¶
停止监听传入连接。现有连接不受影响,但任何新连接将被拒绝。
另请参阅
PySide2.QtNetwork.QLocalServer.
errorString
(
)
¶
unicode
返回人类可读消息适合当前报告错误通过
serverError()
. If no suitable string is available, an empty string is returned.
另请参阅
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
对象。
套接字是作为服务器子级创建的,意味着它会被自动删除当
QLocalServer
对象被销毁。当采用完成后明确删除对象仍是好主意,以避免浪费内存。
None
被返回若在没有待决连接时调用此函数。
PySide2.QtNetwork.QLocalServer.
removeServer
(
name
)
¶
name – unicode
bool
移除任何服务器实例可能导致调用
listen()
to fail and returns
true
若成功;否则返回
false
。此函数意味着从崩溃恢复,当先前服务器实例尚未被清理时。
在 Windows,此函数什么都不做;在 Unix,它移除套接字文件给定通过
name
.
警告
小心避免移除正运行实例的套接字。
PySide2.QtNetwork.QLocalServer.
serverError
(
)
¶
SocketError
返回最后发生的错误类型或
NoError
.
另请参阅
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
另请参阅
PySide2.QtNetwork.QLocalServer.
socketDescriptor
(
)
¶
qintptr
返回服务器用于监听传入指令的本机套接字描述符,或 -1 若服务器未监听。
描述符类型从属平台:
在 Windows,返回值是 Winsock 2 套接字句柄 .
采用 WinRT 并启用 INTEGRITY 时,返回值为
QTcpServer
套接字描述符且类型定义由
socketDescriptor
.
在所有其它像 UNIX 操作系统,类型是表示监听套接字的文件描述符。
另请参阅
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,此函数不会超时。