Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QBluetoothL2CapDatagramSocket Class Reference
[QtBluetoothModule]

The QBluetoothL2CapDatagramSocket class represents an L2CAP Datagram Socket. More...

    #include <QBluetoothL2CapDatagramSocket>

Inherits QBluetoothAbstractSocket.

Public Functions

Additional Inherited Members


Detailed Description

The QBluetoothL2CapDatagramSocket class represents an L2CAP Datagram Socket.

The Bluetooth L2CAP protocol provides reliable connection-oriented and unreliable connectionless data services. It is a lower layer protocol than RFCOMM.

PSM stands for Port and Service Multiplexer. The PSM value can be any odd value the range of 1-32765. For more information please see Bluetooth Specification Version 2.0 + EDR [vol 4] page 45.

The implementation of L2CAP Datagram protocol under Linux uses sockets, and is in general very similar to UDP socket programming.

The most common way to use this class is to call connect() and then write() and read() to write and read the data. If you only wish to receive data, call bind() and use the readDatagram() function.

Note that unlike UDP, the L2Cap Datagram socket must be connected first by using connect().

Note that special attention should be paid to the incoming and outgoing MTU sizes. These determine in what size chunks the data should be read / written.

NOTE: The socket is not buffered. All reads and writes happen immediately. The user must be prepared to deal with conditions where no more data could be read/written to the socket.

See also QBluetoothAbstractSocket.


Member Function Documentation

QBluetoothL2CapDatagramSocket::QBluetoothL2CapDatagramSocket ( QObject * parent = 0 )

Constructs a new QBluetoothL2CapDatagramSocket object. The parent parameter is passed to the QObject constructor.

QBluetoothL2CapDatagramSocket::~QBluetoothL2CapDatagramSocket ()

Destroys the socket.

bool QBluetoothL2CapDatagramSocket::bind ( const QBluetoothAddress & local, int psm, int mtu = 672 )

Binds an L2CAP socket to a specific local address and psm, returning true if successful; otherwise returns false. The mtu specifies the MTU to use.

bool QBluetoothL2CapDatagramSocket::connect ( const QBluetoothAddress & local, const QBluetoothAddress & remote, int psm, int incomingMtu = 672, int outgoingMtu = 672 )

Attempts to open a L2CAP connection between the local device with address local and the remote device with address remote. The L2CAP PSM to use is given by psm. This function should generally return immediately, and the socket will enter into the ConnectingState.

The incomingMtu and outgoingMtu represent the MTU sizes to use for incoming and outgoing data respectively.

The function returns true if the connection could be started, and false otherwise.

Note that the connection could still fail, the state of the socket will be sent in the stateChanged() signal.

See also connected(), stateChanged(), and waitForConnected().

int QBluetoothL2CapDatagramSocket::incomingMtu () const

Returns the MTU for incoming data. The underlying implementation will accept data packets of size no bigger than the incoming MTU. The MTU information is provided so that the read buffer size can be set appropriately.

See also outgoingMtu().

bool QBluetoothL2CapDatagramSocket::isAuthenticated () const

Returns true if the socket is authenticated.

See also securityOptions() and isEncrypted().

bool QBluetoothL2CapDatagramSocket::isEncrypted () const

Returns true if the socket is encrypted.

See also securityOptions() and isAuthenticated().

QBluetoothAddress QBluetoothL2CapDatagramSocket::localAddress () const

Returns the address of the local device. If the socket is not currently connected or bound, returns QBluetoothAddress::invalid.

See also localPsm().

int QBluetoothL2CapDatagramSocket::localPsm () const

Returns the PSM that the socket is bound to on the local device. If the socket is not bound, returns -1

See also localAddress().

int QBluetoothL2CapDatagramSocket::outgoingMtu () const

Returns the MTU for outgoing data. The underlying implementation will accept outgoing data packets of size no bigger than the outgoing MTU.

See also incomingMtu().

qint64 QBluetoothL2CapDatagramSocket::readDatagram ( char * data, qint64 maxSize, QBluetoothAddress * address = 0, int * psm = 0 )

Reads a datagram from the socket. The data specifies the pointer to a buffer of at least maxSize. The address and psm parameters specify where to store the address and psm of the remote device that sent the datagram. The result is discarded if address or psm are NULL.

If the data buffer maxSize is smaller than the incoming MTU, the data that does not fit will be discarded.

Note: Some Linux implementations do not currently return remote address information.

See also incomingMtu().

QBluetoothAddress QBluetoothL2CapDatagramSocket::remoteAddress () const

Returns the address of the remote device. If the socket is not currently connected, returns QBluetoothAddress::invalid.

See also remotePsm().

int QBluetoothL2CapDatagramSocket::remotePsm () const

Returns the PSM of the remote device. If the socket is not currently connected, returns -1.

See also remoteAddress().

QBluetooth::SecurityOptions QBluetoothL2CapDatagramSocket::securityOptions () const

Returns the security options currently active for the socket.

See also setSecurityOptions(), isAuthenticated(), and isEncrypted().

bool QBluetoothL2CapDatagramSocket::setSecurityOptions ( QBluetooth::SecurityOptions options )

Sets the security options on the socket to options. Returns true if the options could be set successfully and false otherwise.

See also securityOptions(), isAuthenticated(), and isEncrypted().


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3