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;
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;
}
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 );
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 );
// 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
Re: sharing and sending/transfer image file between 2 devices using sockets
2009-01-26, 18:14#2
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.
Re: sharing and sending/transfer image file between 2 devices using sockets
2009-01-26, 18:29#3
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....
Re: sharing and sending/transfer image file between 2 devices using sockets
2009-01-26, 20:04#4
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