QLocalServer

Inheritance diagram of QLocalServer

Synopsis

Functions

Virtual functions

Signals

Static functions

Detailed Description

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

This class makes it possible to accept incoming local socket connections.

Call 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.

Call PySide.QtNetwork.QLocalServer.nextPendingConnection() to accept the pending connection as a connected PySide.QtNetwork.QLocalSocket . The function returns a pointer to a PySide.QtNetwork.QLocalSocket that can be used for communicating with the client.

If an error occurs, 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.

When listening for connections, the name which the server is listening on is available through PySide.QtNetwork.QLocalServer.serverName() .

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

Although 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])
Parameters:parentPySide.QtCore.QObject

Create a new local socket server with the given 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()
Return type:unicode

Returns the human-readable message appropriate to the current error reported by PySide.QtNetwork.QLocalServer.serverError() . If no suitable string is available, an empty string is returned.

PySide.QtNetwork.QLocalServer.fullServerName()
Return type:unicode

Returns the full path that the server is listening on.

Note: This is platform specific

PySide.QtNetwork.QLocalServer.hasPendingConnections()
Return type:PySide.QtCore.bool

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

PySide.QtNetwork.QLocalServer.isListening()
Return type:PySide.QtCore.bool

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

PySide.QtNetwork.QLocalServer.listen(name)
Parameters:name – unicode
Return type:PySide.QtCore.bool

Tells the server to listen for incoming connections on name . If the server is currently listening then it will return false. Return true on success otherwise false.

name can be a single name and PySide.QtNetwork.QLocalServer will determine the correct platform specific path. 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()
Return type:PySide.QtCore.int

Returns the maximum number of pending accepted connections. The default is 30.

PySide.QtNetwork.QLocalServer.newConnection()
PySide.QtNetwork.QLocalServer.nextPendingConnection()
Return type:PySide.QtNetwork.QLocalSocket

Returns the next pending connection as a connected PySide.QtNetwork.QLocalSocket object.

The socket is created as a child of the server, which means that it is automatically deleted when the PySide.QtNetwork.QLocalServer object is destroyed. It is still a good idea to delete the object explicitly when you are done with it, to avoid wasting memory.

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

static PySide.QtNetwork.QLocalServer.removeServer(name)
Parameters:name – unicode
Return type:PySide.QtCore.bool

Removes any server instance that might cause a call to 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.

On Windows, this function does nothing; on Unix, it removes the socket file given by name .

Warning

Be careful to avoid removing sockets of running instances.

PySide.QtNetwork.QLocalServer.serverError()
Return type:PySide.QtNetwork.QAbstractSocket.SocketError

Returns the type of error that occurred last or NoError.

PySide.QtNetwork.QLocalServer.serverName()
Return type:unicode

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

PySide.QtNetwork.QLocalServer.setMaxPendingConnections(numConnections)
Parameters:numConnectionsPySide.QtCore.int

Sets the maximum number of pending accepted connections to numConnections . PySide.QtNetwork.QLocalServer will accept no more than numConnections incoming connections before PySide.QtNetwork.QLocalServer.nextPendingConnection() is called.

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)
Parameters:msecPySide.QtCore.int
Return type:(retval, timeOut)

Waits for at most 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.

The non-blocking alternative is to connect to the PySide.QtNetwork.QLocalServer.newConnection() signal.

If msec is -1, this function will not time out.