arrays in client server architecture

Login to reply to this topic.
Fri, 2006-01-13 07:02
Joined: 2006-01-13
Forum posts: 3
hi all,

i am building an application dat requires the server to return
a CArrayFixFlat<RBuf> array. How shall i do it?
In client cpp i have written the following:

/*void*/CArrayFixFlat<RBuf>* RCountServ::ShowTeamList()
   {
   CArrayFixFlat<RBuf>* teamList=new (ELeave) CArrayFixFlat<RBuf>(100);
   TPckgBuf<CArrayFixFlat<RBuf>*> pckg(teamList);
   TIpcArgs args(&pckg);
   
   SendReceive(ECountServShowTeam,args);
//   CArrayFixFlat<TElement1>* teamList;
   teamList=pckg();

   return teamList;
/*   _LIT(KFormatString,"%s");
   for(TInt i=0;i<(teamList->Count()-1);i++)
      
      iConsole->Printf(KFormatString,(*teamPlayer)[i]);*/   
   }


The call to the function from client is as follows, this in in doExampleL

   CArrayFixFlat<RBuf>* TeamList=new (ELeave) CArrayFixFlat<RBuf>(100);
   TeamList= countserv.ShowTeamList();
//   _LIT(KFormatString,"%s");
   for(i=0;i<(TeamList->Count()-1);i++)
      console->Printf(/*KFormatString,*/(*TeamList)[i]);   


The server side code is as follows:

void CCountServSession::ShowTeamList(const RMessage2& aMessage)
{

TPckgBuf<CArrayFixFlat<RBuf>*> TeamArrayPckg(iTeamList);
   aMessage.WriteL(0,TeamArrayPckg);
}

I get the follwing runtime errors
1.  User:23
2.  Kern-Exec:0


Please help.

Thanks,
Anobika

Sat, 2006-01-14 14:45
Joined: 2004-11-29
Forum posts: 1233
Re: arrays in client server architecture
Well, you have two problems here.
Both based in the fact that you need to copy the data over the client/server boundary

CArrayFixFlat will allocate its array on the heap.
also RBuf will keep its actual data on the heap.

And the way you have declared it, you will only copy a pointer to the CArrayFixFlat object between client and server, neither the actual array, nor the strings kept by RBufs will be transfered.

So the client will recieve a random pointer that was valid in the server side process, but not in the client process.

You need to figure out a way to "serialize" the array of strings so it can be copied over the client-server boundary.
Its a pain, I know...

Or... you could use a global heap created by a UserHeap::ChunkHeap() call, and open it from both the client and server, and keep your CArrayFixFlat including your RBufs, allocated on this heap.
Then you can pass pointers between the processes like you do now, and it would actually work.
Note: Probably even more of a mess to implement though...  Undecided
Mon, 2006-01-16 16:40
Joined: 2003-10-20
Forum posts: 35
Re: arrays in client server architecture
Because memory boundaries are process, another solution could be to implement client and server into separate threads of the same process.
In such a way they share the same memory address space, but you preserve multitasking.

I often regret my speech, I never regret my silence

  • Login to reply to this topic.