QLocalServer Class
The QLocalServer class provides a local socket based server. More...
| Header: | #include <QLocalServer> |
| qmake: | QT += network |
| Since: | Qt 4.4 |
| Inherits: | QObject |
This class was introduced in Qt 4.4.
Public Types
| enum | SocketOption { NoOptions, UserAccessOption, GroupAccessOption, OtherAccessOption, WorldAccessOption } |
Properties
- socketOptions : SocketOptions
Public Functions
| void | setSocketOptions(QLocalServer::SocketOptions options) |
| QLocalServer::SocketOptions | socketOptions() const |
Detailed Description
This class makes it possible to accept incoming local socket connections.
Call 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.
Call nextPendingConnection() to accept the pending connection as a connected QLocalSocket. The function returns a pointer to a QLocalSocket that can be used for communicating with the client.
If an error occurs, serverError() returns the type of error, and errorString() can be called to get a human readable description of what happened.
When listening for connections, the name which the server is listening on is available through serverName().
Calling close() makes QLocalServer stop listening for incoming connections.
Although 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.
See also QLocalSocket and QTcpServer.
Member Type Documentation
enum QLocalServer::SocketOption
This enum describes the possible options that can be used to create the socket. This changes the access permissions on platforms (Linux, Windows) that support access permissions on the socket. Both GroupAccess and OtherAccess may vary slightly in meanings depending on the platform.
| Constant | Value | Description |
|---|---|---|
QLocalServer::NoOptions | 0x0 | No access restrictions have been set. |
QLocalServer::UserAccessOption | 0x01 | Access is restricted to the same user as the process that created the socket. |
QLocalServer::GroupAccessOption | 0x2 | Access is restricted to the same group but not the user that created the socket on Linux. Access is restricted to the primary group of the process on Windows |
QLocalServer::OtherAccessOption | 0x4 | Access is available to everyone but the user and group that created the socket on Linux. Access is available to everyone on Windows. |
QLocalServer::WorldAccessOption | 0x7 | No access restrictions. |
This enum was introduced or modified in Qt 5.0.
See also socketOptions.
Property Documentation
socketOptions : SocketOptions
The setSocketOptions method controls how the socket operates. For example the socket may restrict access to what user ids can connect to the socket.
These options must be set before listen() is called.
In some cases, such as with Unix domain sockets on Linux, the access to the socket will be determined by file system permissions, and are created based on the umask. Setting the access flags will override this and will restrict or permit access as specified.
Other Unix-based operating systems, such as macOS, do not honor file permissions for Unix domain sockets and by default have WorldAccess and these permission flags will have no effect.
On Windows, UserAccessOption is sufficient to allow a non elevated process to connect to a local server created by an elevated process run by the same user. GroupAccessOption refers to the primary group of the process (see TokenPrimaryGroup in the Windows documentation). OtherAccessOption refers to the well known "Everyone" group.
By default none of the flags are set, access permissions are the platform default.
This property was introduced in Qt 5.0.
Access functions:
| QLocalServer::SocketOptions | socketOptions() const |
| void | setSocketOptions(QLocalServer::SocketOptions options) |
See also listen().