Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.network
Class QLocalServer

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.network.QLocalServer

All Implemented Interfaces:
  QtJambiInterface

    public class QLocalServer

extends QObject

The `QLocalServer` class provides a local socket based server. 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.

Note that this feature is not supported on Windows 9x or Windows CE.

See also:
  `QLocalSocket`, and `QTcpServer`.

Nested Class Summary
`static class` | `QLocalServer.Result`

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Field Summary
`QSignalEmitter.Signal0` | `newConnection` This signal is emitted every time a new connection is available.

Constructor Summary
`QLocalServer()` Create a new local socket server with the given `parent`.
`QLocalServer(QObject parent)` Create a new local socket server with the given `parent`.

Method Summary
`void` | `close()` Stop listening for incoming connections.
`java.lang.String` | `errorString()` Returns the human-readable message appropriate to the current error reported by `serverError()`.
`static QLocalServer` | `fromNativePointer(QNativePointer nativePointer)` This method returns the QLocalServer instance pointed to by `nativePointer`.
`java.lang.String` | `fullServerName()` Returns the full path that the server is listening on.
`boolean` | `hasPendingConnections()` Returns true if the server has a pending connection; otherwise returns false.
`protected void` | `incomingConnection(long socketDescriptor)` This virtual function is called by `QLocalServer` when a new connection is available.
`boolean` | `isListening()` Returns true if the server is listening for incoming connections otherwise false.
`boolean` | `listen(java.lang.String name)` Tells the server to listen for incoming connections on `name`.
`int` | `maxPendingConnections()` Returns the maximum number of pending accepted connections.
`QLocalSocket` | `nextPendingConnection()` Returns the next pending connection as a connected `QLocalSocket` object.
`QAbstractSocket.SocketError` | `serverError()` Returns the type of error that occurred last or `NoError`.
`java.lang.String` | `serverName()` Returns the server name if the server is listening for connections; otherwise returns QString()
`void` | `setMaxPendingConnections(int numConnections)` Sets the maximum number of pending accepted connections to `numConnections`.
`QLocalServer.Result` | `waitForNewConnection()` Waits for at most `msec` milliseconds or until an incoming connection is available.
`QLocalServer.Result` | `waitForNewConnection(int msec)` Waits for at most `msec` milliseconds or until an incoming connection is available.

Methods inherited from class com.trolltech.qt.core.QObject
`childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Field Detail

### newConnection

    public final QSignalEmitter.Signal0 newConnection

  This signal is emitted every time a new connection is available.

See also:
  `hasPendingConnections()`, and `nextPendingConnection()`.

Constructor Detail

### QLocalServer

    public QLocalServer()

  Create a new local socket server with the given `parent`.

See also:
  `listen()`.

### QLocalServer

    public QLocalServer(QObject parent)

  Create a new local socket server with the given `parent`.

See also:
  `listen()`.

Method Detail

### close

    public final void close()

  Stop listening for incoming connections. Existing connections are not effected, but any new connections will be refused.

See also:
  `isListening()`, and `listen()`.

### errorString

    public final java.lang.String errorString()

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

See also:
  `serverError()`.

### fullServerName

    public final java.lang.String fullServerName()

  Returns the full path that the server is listening on.

  Note: This is platform specific

See also:
  `listen()`, and `serverName()`.

### isListening

    public final boolean isListening()

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

See also:
  `listen()`, and `close()`.

### listen

    public final boolean listen(java.lang.String name)

  Tells the server to listen for incoming connections on `name`. If the server is currently listening then it will first `close()`. Return true on success otherwise false.

  `name` can be a single name and `QLocalServer` will determine the correct platform specific path. `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 "\\.\pipe\foo"

  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.

See also:
  `serverName()`, `isListening()`, and `close()`.

### maxPendingConnections

    public final int maxPendingConnections()

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

See also:
  `setMaxPendingConnections()`, and `hasPendingConnections()`.

### serverError

    public final QAbstractSocket.SocketError serverError()

  Returns the type of error that occurred last or `NoError`.

See also:
  `errorString()`.

### serverName

    public final java.lang.String serverName()

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

See also.
  `listen()`, and `fullServerName()`.

### setMaxPendingConnections

    public final void setMaxPendingConnections(int numConnections)

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

  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.

See also:
  `maxPendingConnections()`, and `hasPendingConnections()`.

### hasPendingConnections

    public boolean hasPendingConnections()

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

See also:
  `nextPendingConnection()`, and `setMaxPendingConnections()`.

### incomingConnection

    protected void incomingConnection(long socketDescriptor)

  This virtual function is called by `QLocalServer` when a new connection is available. `socketDescriptor` is the native socket descriptor for the accepted connection.

  The base implementation creates a `QLocalSocket`, sets the socket descriptor and then stores the `QLocalSocket` in an internal list of pending connections. Finally `newConnection()` is emitted.

  Reimplement this function to alter the server's behavior when a connection is available.

See also:
  `newConnection()` , `nextPendingConnection()`, and `QLocalSocket::setSocketDescriptor()`.

### nextPendingConnection

    public QLocalSocket nextPendingConnection()

  Returns the next pending connection as a connected `QLocalSocket` object.

  The socket is created as a child of the server, which means that it is automatically deleted when the `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.

See also:
  `hasPendingConnections()`, `newConnection()` , and `incomingConnection()`.

### fromNativePointer

    public static QLocalServer fromNativePointer(QNativePointer nativePointer)

  This method returns the QLocalServer instance pointed to by `nativePointer`.

### waitForNewConnection

    public final QLocalServer.Result waitForNewConnection(int msec)

  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. `waitForNewConnection()` is mostly useful when there is no event loop available.

  The non-blocking alternative is to connect to the `newConnection()` signal.

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

See also:
  `hasPendingConnections()`, and `nextPendingConnection()`.

### waitForNewConnection

    public final QLocalServer.Result waitForNewConnection()

  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. `waitForNewConnection()` is mostly useful when there is no event loop available.

  The non-blocking alternative is to connect to the `newConnection()` signal.

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

See also:
  `hasPendingConnections()`, and `nextPendingConnection()`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD