# class KLocalSocketServer

###

Module | kdecore
Namespace |
Class | KLocalSocketServer
Inherits | QObject

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>

### methods

- KLocalSocketServer (parent)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  parent | QObject | 0

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

  parent - the parent object

- KLocalSocketServer (a0)

  returns ctor
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  a0 | KLocalSocketServer |

- KLocalSocketServer (a0)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QObject | 0

- close ( )

  returns Nothing

  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.

- errorString ( )

  returns QString

  If an error occurred, return the error message.

- hasPendingConnections ( )

  returns bool

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

- incomingConnection (handle)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  handle | int |

  Internal

- isListening ( )

  returns bool

  Returns true if the socket is listening, false otherwise.

- listen (path, type)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  path | QString |
  type | KLocalSocket.LocalSocketType | 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.

  path - the path to listen on

  type - the local socket type Returns true on success, false otherwise

- localPath ( )

  returns QString

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

- localSocketType ( )

  returns KLocalSocket.LocalSocketType

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

- maxPendingConnections ( )

  returns int

  Returns the value set with setMaxPendingConnections().

- newConnection ( )

  returns Nothing
  SIGNAL ("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.

- nextPendingConnection ( )

  returns KLocalSocket

  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.

- serverError ( )

  returns QAbstractSocket.SocketError

  If an error occurred, return the error code.

- setMaxPendingConnections (numConnections)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  numConnections | int |

  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.

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

- waitForNewConnection (msec)

  returns bool, bool (timedOut)

  Argument | Type | Default
  --- | --- | ---
  msec | int | 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.

  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.