×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    sharing and sending/transfer image file between 2 devices using sockets

    Hi,

    I have an application which should share and transfer images between two devices using sockets. I am using serialization to Externalize the image file at the sending side and Internalize at the receiving end. Following is the snippet from the code so it would be easier to suggest and advise me how to proceed with my problem. I have used the Internalize and Externalize code from one example in Forum Nokia.

    class CImageProtocol
    {
    void CImageProtocol::ExternalizeL( RWriteStream& aStream ) const
    {
    // Write the used protocol version first
    aStream << KProtocolVersion;
    aStream << static_cast<TInt32> ( iImage->Length() );
    aStream << *iImage;
    }

    void CImageProtocol::InternalizeL( RReadStream& aStream )
    {
    // 32 bit buffer
    TInt32 intToken;
    // First check if the data was created by a compatible writer
    aStream >> intToken;

    if( intToken != KProtocolVersion )
    {
    User::Leave( KErrNotSupported );
    }
    // Delete the current values
    delete iImage;
    aStream >> intToken;
    iImage = HBufC::NewL( intToken );
    TPtr pImage = iImage->Des();
    aStream >> pImage;
    }
    }

    class CAppContainerView
    {
    void CAppContainerView::HandleCommandL( TInt aCommand )
    {
    // begin generated region: do not modify [Generated Code]
    TBool commandHandled = EFalse;
    switch ( aCommand )
    { // code to dispatch to the AknView's menu and CBA commands is generated here
    case ETestAppContainerViewGetRemoteImageMenuItemCommand:
    commandHandled = RemoteImage( );
    break;
    default:
    break;
    }

    void CTestAppContainerView:: DoActivateL(
    const TVwsViewId& /*aPrevViewId*/,
    TUid /*aCustomMessageId*/,
    const TDesC8& /*aCustomMessage*/ )
    {

    if ( iTestAppContainer == NULL )
    {
    iTestAppContainer = CTestAppContainer::NewL( ClientRect(), NULL, this );
    //Creates Test App Engine
    iEngine = CTestAppEngine::NewL( );
    //when the socket is used as client
    iClientSocketEngine = CSocketEngine::NewL( *iTestAppContainer, *iEngine );
    //when the socket is used as server
    iServerSocketEngine = CSocketEngine::NewL( *iTestAppContainer, *iEngine );

    iEngine->SetSocketEngine( iServerSocketEngine );

    iEngine->SetContainer( iTestAppContainer );
    iTestAppContainer->SetMopParent( this );
    iServerSocketEngine->SetSendSocketEngine( iClientSocketEngine );
    iClientSocketEngine->SetReceiveSocketEngine( iServerSocketEngine );

    }

    TBool CTestAppContainerView::LocalImage()
    {
    // TBuf8, not TBuf. Storage format is not dependent on the machine architecture
    TBuf8<KBufferSize> storage;
    RDesWriteStream writer( storage );
    // Whatever happens, resources will be cleaned up correctly
    CleanupClosePushL( writer );

    // Create the source object
    _LIT(KImageFile,"C:\\imageToBeTransferred.jpg");
    iImageProtocol = CImageProtocol::NewLC( KImageFile );

    TInt err = KErrNone;

    // Store the source object
    writer << *iImageProtocol;

    // Close the stream. It also commits changes
    CleanupStack::PopAndDestroy( &writer );
    RemoteDir( );
    }

    /**
    * remote image
    */
    TBool CTestAppContainerView::RemoteImage( )
    {
    TBuf8<KBufferSize> storage;
    // And read the data to the different object
    CImageProtocol* dest = CImageProtocol::NewLC( KNullDesC );
    RDesReadStream reader ( storage );
    CleanupClosePushL( reader );
    reader >> *iImageProtocol;

    CleanupStack::PopAndDestroy( &reader );
    }
    }



    The problem I am facing is that how can I give the image data to the socket and read it on the receiving end. Any sort of help would be appreciated or you can modify the above code to correct/suggest me the possible solution.

    Thanks

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: sharing and sending/transfer image file between 2 devices using sockets

    For checking if the externalize-internalize pair works, you can use the simplest file (RFile), where you can read and write 8-bit descriptors, just like you could do with RSocket.
    For using sockets, you can find some ideas in Chat example bundled with recent SDK-s. It shows communication over both TCP/IP and RFCOMM/Bluetooth sockets.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    Re: sharing and sending/transfer image file between 2 devices using sockets

    Yes the externalize and internalize works fine as I could print text in local host both as original text before externalizing and then the cloned text after internalizing at the other end. And Yes, I checked the Chat app but the problem is that in that string are sent while I want to transfer images... being a newbie I wonder how could I make it work for image transfer. suggestions please....

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: sharing and sending/transfer image file between 2 devices using sockets

    Check once more. Everything that can be sent over RSocket has to be/be converted to/be packed a 8-bit descriptor. And a 8-bit descriptor is exactly what you have.
    More about descriptors: http://descriptors.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×