Detailed Description
The QBluetoothL2CapSocket class represents an L2CAP client socket.
The Bluetooth L2CAP protocol provides reliable connection-oriented and unreliable connectionless data services. It is a lower layer protocol than RFCOMM. The implementation of L2CAP protocol under Linux uses sockets, and is in general very similar to TCP socket programming.
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 PSM and address of the connected peer are fetched by calling remotePsm() and remoteAddress() respectively. The localAddress() returns the address of the local device being used by the socket.
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. If preserving the record boundaries when reading is important, then the read buffer size should be set to the value of incomingMtu() using setReadBufferSize() when the socket is connected. If record boundaries are important when writing, the data should only be fed one packet of size <= outgoingMtu() at a time by using write and then waiting for the bytesWritten() signal before sending more data.
See also QBluetoothL2CapServer.
Member Function Documentation
QBluetoothL2CapSocket::QBluetoothL2CapSocket ( QObject * parent = 0 )
Constructs a new QBluetoothL2CapSocket object. The parent parameter is passed to the QObject constructor.
QBluetoothL2CapSocket::~QBluetoothL2CapSocket ()
Destroys the socket.
bool QBluetoothL2CapSocket::connect ( const QBluetoothAddress & local, const QBluetoothAddress & remote, int psm, int incomingMtu = 672, int outgoingMtu = 672, QBluetooth::SecurityOptions options = 0 )
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. These parameters should only be considered hints and are subject to negotiation by the underlying stack implementation. If the connection succeeds the actual MTUs should be queried by using incomingMtu() and outgoingMtu() methods.
Optionally, the client can request that that the connection be secured by specifying the options parameter. NOTE: This feature might not work under some systems.
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 state(), connected(), and waitForConnected().
int QBluetoothL2CapSocket::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 QBluetoothL2CapSocket::isAuthenticated () const
Returns true if the socket is authenticated.
See also securityOptions() and isEncrypted().
bool QBluetoothL2CapSocket::isEncrypted () const
Returns true if the socket is encrypted.
See also securityOptions() and isAuthenticated().
QBluetoothAddress QBluetoothL2CapSocket::localAddress () const
Returns the address of the local device. If the socket is not currently connected, returns QBluetoothAddress::invalid.
See also remotePsm() and remoteAddress().
int QBluetoothL2CapSocket::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().
QBluetoothAddress QBluetoothL2CapSocket::remoteAddress () const
Returns the address of the remote device. If the socket is not currently connected, returns QBluetoothAddress::invalid.
See also remotePsm() and localAddress().
int QBluetoothL2CapSocket::remotePsm () const
Returns the PSM of the remote device. If the socket is not currently connected, returns -1.
See also remoteAddress() and localAddress().
Returns the security options currently active for the socket.
See also isAuthenticated() and isEncrypted().