Transferring Data to the Remote Device

Context

When the MLlcpLinkListener::LlcpRemoteFound() callback is called, the application issues the CMyOwnLlcpApplication::SendHelloWorldText() to send the "Hello World!" ASCII text.

Steps

  • Call the CMyOwnLlcpApplication::SendHelloWorldText() method as shown in the following code snippet:

    // CMyOwnLlcpApplication::SendHelloWorldText()
    // -----------------------------------------------------------------------------
    //
    TInt CMyOwnLlcpApplication::SendHelloWorldText()
        {
        TInt error = KErrNone;
        
        if ( iLocalConnection )
            {
            iLocalConnection->Transfer( *this, _L8( "Hello World!" ) );
            }
        else
            {
            // An LLCP link is not established, cannot send any data.
            error = KErrNotReady;
            }
            
        return error;
        }
    // -----------------------------------------------------------------------------
    // End of CMyOwnLlcpApplication::SendHelloWorldText()
    

    If the iLocalConnection object has already been created, the MLlcpConnLessTransporter::Transmit() method is called. If iLocalConnection is NULL, the CMyOwnLlcpApplication::LlcpRemoteFound() method is not called and no LLCP link between the local and remote devices is established.

    The actual data transfer in the COwnLlcpConnection::Transfer() method is shown in the following code snippet:

    // COwnLlcpConnection::Transfer()
    // -----------------------------------------------------------------------------
    //
    TInt COwnLlcpConnection::Transfer( MLlcpTransmitCb& aLlcpTransmitCb, const TDesC8& aData )
        {
        TInt error = KErrNone;
        
        // Copying the data to an internal buffer. 
        iTransmitBuf.Zero();
        error = iTransmitBuf.ReAlloc( aData.Length() );
        
        if ( error == KErrNone )
            {
            iTransmitBuf.Append( aData );
            
            if ( iActionState == EIdle )
                {
                // Sending the data
                iConnection->Transmit( iStatus, iTransmitBuf );
                SetActive();
                iActionState = ETransmitting;
                
                iLlcpTransmitCb = &aLlcpTransmitCb
                }
            else
                {
                // Already sending or receiving the data
                error = KErrInUse;
                }
            }
            
        return error;
        }
    // -----------------------------------------------------------------------------
    // End of COwnLlcpConnection::Transfer()
    
    

    The COwnLlcpConnection::Transfer() method copies descriptor to its internal buffer and then the data transfer occurs immediately between the local and remote device.

    Note:

    • The COwnLlcpConnection::Transfer() method cannot start transferring data if there is already a transfer or a receive request pending. In such a scenario, KErrInUse is returned. This means that the COwnLlcpConnection object does not support simultaneous transferring and receiving. However, the MLlcpConnLessTransporter object supports simultaneous data transferring and data receiving between the local and remote devices.

    • The maximum amount of data that MLlcpConnLessTransporter::Transmit() can handle is the value returned by MLlcpConnLessTransporter::SupportedDataLength(). If the data is greater than this value, clients of MLlcpConnLessTransporter::Transmit()must send the data in multiple packets. The minimum size of MLlcpConnLessTransporter::SupportedDataLength() is 128 bytes.

    The following diagram illustrates the sequence of the data transferring:

    Figure: Sequence diagram of data transferring