IPC Client/Server with complex data communication
| Fri, 2005-09-30 11:49 | |
|
Hi all,
Which classes do I need, if I like to send/receive complex large amount of data between applications? I mean arrays, objects, streams etc. with variable size, and if the client is connected the server can send data to it without request. I check the sdk, but didnt find any suitable... Am I blind? Thank you. Ro0p |
|






Forum posts: 1379
Firstly, you're not blind, its just not very well documented.
Essentially, the only thing that can be transfered between client & server are descriptors. However, the TPkg classes make it possiable to eassialy wrap up most classes as a descriptor.
If that doesn't fit the bill, the best thing to do is implment a shared heap - so the clients basically use the servers heap, and remove the need for IPC.
In regard to the last bit: no. The only way the server can send data to the client is via "polling". i.e. the client asks the sever to send data to it.
didster
Forum posts: 131
It seems too difficult for me...
I'll try it with TCP/IP. Do you think it will work?
Thanks.
Ro0p
Forum posts: 7
In the "Pc" world communication via sockets is OK if the speed is not so important.
In Symbian too you can pass data via sockets but there still must be one server where to connect, and the clients must know the port where to connect.
Quite a problem if app1,app2,app3 and app4 wants to transfer data, which is the server?
But in the Symbian there is other ways to transfer data between apps. If the data amounts you want to pass between apps are quite a minimals
like integers or buffers < 512 bytes you can use the Publish and Subscribe.
It is event based communication API but it can be also use to pass data between apps.
The P&S implementation is quite a simple. Try find more information from forum.nokia.com.
http://www.forum.nokia.com/html_reader/main/1,,6020,00.html
Forum posts: 7
Basically reading the heap can done from other thread or other process. But this example just shows how to do it.
Simple and effective way to pass data between threads.
#define _HEAP_MAX_SIZE 512
#define _HEAP_COMMITTED_SIZE 128
_LIT(KMyHeap,"my_heap");
void MainL()
{
_LIT8(KData,"Hello world!");
TBuf8<128> src8;
TBuf8<128> dst8;
TBuf16<128> dst16;
src8.Append(KData);
CTester* tester = CTester::NewL();
TRAPD(err,
{
tester->CreateHeapL(_HEAP_MAX_SIZE,_HEAP_COMMITTED_SIZE);
tester->WriteToHeapL(src8);
tester->ReadFromHeapL(dst8,src8.Size());
});
//Check error
User::LeaveIfError(err);
//Ascii to Uni
dst16.Copy(dst8);
//MACRO
PRINT(dst16);
//Wait for any key press MACRO
WAITKEY()
delete tester;
}
//
//WriteToHeapL(TDesC8& aData)
//
void CTester::CreateHeapL(TUint32 aMaxSize, TUint32 aCommittedSize)
{
if(aMaxSize<0 || aCommittedSize < 0 || aMaxSize < aCommittedSize)
{
//Cancel the operation
User::Leave(KErrCancel);
}
// Create a Chunk
RChunk chunk;
User::LeaveIfError ( chunk.CreateGlobal(KMyHeap,aCommittedSize,aMaxSize) );
}
//
//WriteToHeapL(TDesC8& aData)
//
void CTester::WriteToHeapL(TDesC8& aData)
{
// Create a Chunk
RChunk chunk;
// Open the Chunk with full read/write access
User::LeaveIfError ( chunk.OpenGlobal(KMyHeap,EFalse));
// Get the base pointer of the Global chunk
TUint8 *ptr = chunk.Base();
// Copy data into the chunk
Mem::Copy(ptr,(TAny *)aData.Ptr(),aData.Size());
//Close the chunk handle
chunk.Close();
}
//
//ReadFromHeapL(TDes8& aData, TUint a_size)
//
void CTester::ReadFromHeapL(TDes8& aData, TUint a_size)
{
// Create a Chunk of space HEAP_MAX_SIZE
RChunk chunk;
// Open the Chunk with full read/write access
User::LeaveIfError(chunk.OpenGlobal(KMyHeap,EFalse));
// Copy data into the chunk
aData.FillZ();
Mem::Copy((TAny *)aData.Ptr(),(TAny *)chunk.Base(), a_size);
aData.SetLength( a_size );
//Close the chunk handle
chunk.Close();
}
Forum posts: 11
I suppose this has a problem, After the mem::copy the Base() pointer position is altered in the RChunk. Did you not face this problem ?
Forum posts: 114
Hi,
You can use RMsgQueue to send/receive data across thread/process. If the size of data is huge it is good to use RChunk as tl mentioned. Using RMsgQueue data can be sent without needing to know anyone is interested in it or not.
Chao,
Raghav
Forum posts: 672
The example above didn't contain any code to manage synchronous access to the global heap. Once you (properly) start to use them, things may get difficult, if you do not implement it correctly. Check out RMutex, RCriticalSection, RSemaphore etc.