KLocalSocketServer

KDE 4.5 PyKDE API Reference

- KDE's Python API

# KLocalSocketServer Class Reference

`from PyKDE4.kdecore import *`

Inherits: QObject

## Detailed Description

KLocalSocketServer KLocalSocketServer allows one to create a listening local socket and accept incoming connections

On some platforms, local sockets are a kind of streaming socket that can be used to transmit and receive data just like Internet (TCP) streaming sockets. The difference is that they remain local to the host running them and cannot be accessed externally. They are also very fast and (in theory) consume less resources than standard TCP sockets.

KLocalSocketServer allows you to create the listening (i.e., passive) end of this local socket and accept incoming connections from users of KLocalSocket. It supports the same kind of socket types that KLocalSocket does (see KLocalSocket.LocalSocketType).

Author:
  Thiago Macieira <thiago@kde.org>

## Signals
| newConnection ()
## Methods
| __init__ (self, QObject parent=0)
| __init__ (self, KLocalSocketServer a0)
| close (self)
QString | errorString (self)
bool | hasPendingConnections (self)
| incomingConnection (self, int handle)
bool | isListening (self)
bool | listen (self, QString path, KLocalSocket.LocalSocketType type=KLocalSocket.UnixSocket)
QString | localPath (self)
KLocalSocket.LocalSocketType | localSocketType (self)
int | maxPendingConnections (self)
KLocalSocket | nextPendingConnection (self)
QAbstractSocket.SocketError | serverError (self)
| setMaxPendingConnections (self, int numConnections)
bool, bool timedOut | waitForNewConnection (self, int msec=0)

## Signal Documentation

newConnection | ( |  | ) |

The newConnection() signal is emitted whenever a new connection is ready and has been accepted. Whenever it is emitted, calling nextPendingConnection() will return a valid object at least once.

Signal syntax:
  `QObject.connect(source, SIGNAL("newConnection()"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent=0
| ) |  |  |

Creates a KLocalSocketServer object with parent as the parent object. The object is created without binding to any address.

Parameters:

  | parent | the parent object

__init__ | ( | self, |
|  | KLocalSocketServer | a0
| ) |  |  |

close | ( |  | self ) |

Closes the socket. No further connections will be accepted, but connections that were already pending can still be retrieved with nextPendingConnection().

Connections that were accepted and are already open will not be affected.

QString errorString | ( |  | self ) |

If an error occurred, return the error message.

bool hasPendingConnections | ( |  | self ) |

Returns true if a new socket can be received with nextPendingConnection().

incomingConnection | ( | self, |
|  | int | handle
| ) |  |  |

bool isListening | ( |  | self ) |

Returns true if the socket is listening, false otherwise.

bool listen | ( | self, |
|  | QString | path,
|  | KLocalSocket.LocalSocketType | type=KLocalSocket.UnixSocket
| ) |  |  |

Binds this socket to the address path and starts listening there.

If type is KLocalSocket.UnixSocket, path is treated as a Unix filesystem path and the calling user must have permission to create the named directory entry (that is, the user must have write permission to the parent directory, etc.)

If type is KLocalSocket.AbstractUnixSocket, path is just a name that can be anything. It'll be converted to an 8-bit identifier just as if it were a file path, but filesystem restrictions do not apply.

This function returns true if it succeeded in binding the socket to path and placing it in listen mode. It returns false otherwise.

Parameters:

  | path | the path to listen on
  | type | the local socket type

Returns:
  true on success, false otherwise

QString localPath | ( |  | self ) |

Returns the address of this socket if it is listening on, or QString() if it is not listening.

KLocalSocket.LocalSocketType localSocketType | ( |  | self ) |

Returns the socket type that this socket is listening on. If it is not listening, returns QAbstractSocket.UnknownLocalSocketType.

int maxPendingConnections | ( |  | self ) |

Returns the value set with setMaxPendingConnections().

KLocalSocket nextPendingConnection | ( |  | self ) |

Returns a new socket if one is available or 0 if none is.

Note that the objects returned by this function will have the current KLocalSocketServer object as its parent. You may want to reparent the accepted objects if you intend them to outlive the current object.

QAbstractSocket.SocketError serverError | ( |  | self ) |

If an error occurred, return the error code.

setMaxPendingConnections | ( | self, |
|  | int | numConnections
| ) |  |  |

Sets the maximum number of connections that KLocalSocketServer will accept on your behalf and keep queued, ready to be retrieved with nextPendingConnection(). If you set @p numConnections to 0, hasPendingConnections() will always return false. You can still use waitForNewConnection(), though.

Parameters:

  | numConnections | the number of connections to accept and keep queued.

bool, bool timedOut waitForNewConnection | ( | self, |
|  | int | msec=0
| ) |  |  |

Suspends the execution of the calling thread for at most @p msec milliseconds and wait for a new socket connection to be accepted (whichever comes first). If no new socket connection is received within msec milliseconds, consider this a time-out and set the boolean pointed by timedOut to false (if it's not 0).

If msec is 0, this call will not block, but will simply poll the system to check if a new connection has been received in the background.

Use msec value of -1 to block indefinitely.

Parameters:

  | msec | the time in milliseconds to block at most (-1 to block forever)
  | timedOut | points to a boolean that will be set to true if a timeout did occur

Returns:
  true if a new connection has been accepted or false if an error occurred or if the operation timed out.