|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QLocalSocket Class Reference
[QtNetwork module]

The QLocalSocket class provides a local socket. More...

     #include <QLocalSocket>

Inherits QIODevice.

This class was introduced in Qt 4.4.

- List of all members, including inherited members

### Public Types

- enum LocalSocketError { ConnectionRefusedError, PeerClosedError, ServerNotFoundError, SocketAccessError, ..., UnknownSocketError }
- enum LocalSocketState { UnconnectedState, ConnectingState, ConnectedState, ClosingState }

### Public Functions

- QLocalSocket ( QObject * parent = 0 )
- ~QLocalSocket ()
- void abort ()
- virtual qint64 bytesAvailable () const
- virtual qint64 bytesToWrite () const
- virtual bool canReadLine () const
- virtual void close ()
- void connectToServer ( const QString & name, OpenMode openMode = ReadWrite )
- void disconnectFromServer ()
- LocalSocketError error () const
- bool flush ()
- QString fullServerName () const
- bool isValid () const
- qint64 readBufferSize () const
- QString serverName () const
- void setReadBufferSize ( qint64 size )
- bool setSocketDescriptor ( quintptr socketDescriptor, LocalSocketState socketState = ConnectedState, OpenMode openMode = ReadWrite )
- quintptr socketDescriptor () const
- LocalSocketState state () const
- virtual bool waitForBytesWritten ( int msecs = 30000 )
- bool waitForConnected ( int msecs = 30000 )
- bool waitForDisconnected ( int msecs = 30000 )
- virtual bool waitForReadyRead ( int msecs = 30000 )

- 32 public functions inherited from QIODevice
- 29 public functions inherited from QObject

### Signals

- void connected ()
- void disconnected ()
- void error ( QLocalSocket::LocalSocketError socketError )
- void stateChanged ( QLocalSocket::LocalSocketState socketState )

- 4 signals inherited from QIODevice
- 1 signal inherited from QObject

### Protected Functions

- virtual qint64 readData ( char *, qint64 )
- virtual qint64 writeData ( const char *, qint64 )

- 5 protected functions inherited from QIODevice
- 7 protected functions inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 5 static public members inherited from QObject

## Detailed Description

The QLocalSocket class provides a local socket.

On Windows this is a named pipe and on Unix this this is a local domain socket.

If an error occurs, socketError() returns the type of error, and errorString() can be called to get a human readable description of what happened.

Although QLocalSocket is designed for use with an event loop, it's possible to use it without one. In that case, you must use waitForConnected(), waitForReadyRead(), waitForBytesWritten(), and waitForDisconnected() which blocks until the operation is complete or the timeout expires.

Note that this feature is not supported on Windows CE.

See also QLocalServer.

## Member Type Documentation

### enum QLocalSocket::LocalSocketError

The LocalServerError enumeration represents the errors that can occur. The most recent error can be retrieved through a call to QLocalSocket::error().

Constant | Value | Description
--- | --- | ---
`QLocalSocket::ConnectionRefusedError` | `QAbstractSocket::ConnectionRefusedError` | The connection was refused by the peer (or timed out).
`QLocalSocket::PeerClosedError` | `QAbstractSocket::RemoteHostClosedError` | The remote socket closed the connection. Note that the client socket (i.e., this socket) will be closed after the remote close notification has been sent.
`QLocalSocket::ServerNotFoundError` | `QAbstractSocket::HostNotFoundError` | The local socket name was not found.
`QLocalSocket::SocketAccessError` | `QAbstractSocket::SocketAccessError` | The socket operation failed because the application lacked the required privileges.
`QLocalSocket::SocketResourceError` | `QAbstractSocket::SocketResourceError` | The local system ran out of resources (e.g., too many sockets).
`QLocalSocket::SocketTimeoutError` | `QAbstractSocket::SocketTimeoutError` | The socket operation timed out.
`QLocalSocket::DatagramTooLargeError` | `QAbstractSocket::DatagramTooLargeError` | The datagram was larger than the operating system's limit (which can be as low as 8192 bytes).
`QLocalSocket::ConnectionError` | `QAbstractSocket::NetworkError` | An error occurred with the connection.
`QLocalSocket::UnsupportedSocketOperationError` | `QAbstractSocket::UnsupportedSocketOperationError` | The requested socket operation is not supported by the local operating system.
`QLocalSocket::UnknownSocketError` | `QAbstractSocket::UnknownSocketError` | An unidentified error occurred.

### enum QLocalSocket::LocalSocketState

This enum describes the different states in which a socket can be.

Constant | Value | Description
--- | --- | ---
`QLocalSocket::UnconnectedState` | `QAbstractSocket::UnconnectedState` | The socket is not connected.
`QLocalSocket::ConnectingState` | `QAbstractSocket::ConnectingState` | The socket has started establishing a connection.
`QLocalSocket::ConnectedState` | `QAbstractSocket::ConnectedState` | A connection is established.
`QLocalSocket::ClosingState` | `QAbstractSocket::ClosingState` | The socket is about to close (data may still be waiting to be written).

See also QLocalSocket::state().

## Member Function Documentation

### QLocalSocket::QLocalSocket ( QObject * parent = 0 )

Creates a new local socket. The parent argument is passed to QObject's constructor.

### QLocalSocket::~QLocalSocket ()

Destroys the socket, closing the connection if necessary.

### void QLocalSocket::abort ()

### qint64 QLocalSocket::bytesAvailable () const `[virtual]`

### qint64 QLocalSocket::bytesToWrite () const `[virtual]`

### bool QLocalSocket::canReadLine () const `[virtual]`

### void QLocalSocket::close () `[virtual]`

### void QLocalSocket::connectToServer ( const QString & name, OpenMode openMode = ReadWrite )

### void QLocalSocket::connected () `[signal]`

This signal is emitted after connectToServer() has been called and a connection has been successfully established.

See also connectToServer() and disconnected().

### void QLocalSocket::disconnectFromServer ()

### void QLocalSocket::disconnected () `[signal]`

This signal is emitted when the socket has been disconnected.

See also connectToServer(), disconnectFromServer(), abort(), and connected().

### LocalSocketError QLocalSocket::error () const

### void QLocalSocket::error ( QLocalSocket::LocalSocketError socketError ) `[signal]`

This is an overloaded member function, provided for convenience.

This signal is emitted after an error occurred. The socketError parameter describes the type of error that occurred.

QLocalSocket::LocalSocketError is not a registered metatype, so for queued connections, you will have to register it with Q_REGISTER_METATYPE.

See also error() and errorString().

### bool QLocalSocket::flush ()

### QString QLocalSocket::fullServerName () const

Returns the server path that the socket is connected to.

Note: This is platform specific

See also connectToServer() and serverName().

### bool QLocalSocket::isValid () const

### qint64 QLocalSocket::readBufferSize () const

See also setReadBufferSize().

### qint64 QLocalSocket::readData ( char *, qint64 ) `[virtual protected]`

### QString QLocalSocket::serverName () const

Returns the name of the peer as specified by connectToServer(), or an empty QString if connectToServer() has not been called or it failed.

See also connectToServer() and fullServerName().

### void QLocalSocket::setReadBufferSize ( qint64 size )

See also readBufferSize().

### bool QLocalSocket::setSocketDescriptor ( quintptr socketDescriptor, LocalSocketState socketState = ConnectedState, OpenMode openMode = ReadWrite )

See also socketDescriptor().

### quintptr QLocalSocket::socketDescriptor () const

See also setSocketDescriptor().

### LocalSocketState QLocalSocket::state () const

Returns the state of the socket.

See also error().

### void QLocalSocket::stateChanged ( QLocalSocket::LocalSocketState socketState ) `[signal]`

This signal is emitted whenever QLocalSocket's state changes. The socketState parameter is the new state.

QLocalSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_REGISTER_METATYPE.

See also state().

### bool QLocalSocket::waitForBytesWritten ( int msecs = 30000 ) `[virtual]`

### bool QLocalSocket::waitForConnected ( int msecs = 30000 )

### bool QLocalSocket::waitForDisconnected ( int msecs = 30000 )

### bool QLocalSocket::waitForReadyRead ( int msecs = 30000 ) `[virtual]`

### qint64 QLocalSocket::writeData ( const char *, qint64 ) `[virtual protected]`