×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Problems with client/server data transfer

    Hi,

    I have a problem related to data transfer between a client and a server, which I don't seem to really understand. The problem is that even though I think I am doing everything as I am supposed to when trying to read data (for a simple class) from client's address space I only get garbage on the server side as a result.

    I'll explain my code in more detail in the following. My program is structured in a way that the client and the server run on the same process, but in different threads. The code in the client side handle to the server (derived from RSessionBase) is as follows.

    Member variable in the client side handle:

    Code:
    TParams iParams; // TParams is a simple class with data only members
    The part of code in the handle which dispatches the request to the server:

    Code:
    // Put the data descriptor(i.e. source descriptor) into parameters for the server
    TPtr8 ptr(reinterpret_cast<TUint8*>(&iParams), sizeof(iParams), sizeof(iParams));
    TAny* p[4];
    p[0] = static_cast<TAny*>(&ptr);
    p[1] = 0;
    p[2] = 0;
    p[3] = 0;
    
    // Make asynchronous request to the server
    SendReceive(EServerRequestId, &p[0], aStatus);
    Member variable in the class derived from CSession and is handling the request from the client:

    Code:
    TParams iParams; // TParams is a simple class with data only members
    The part of the code on the session class, which tries to read the data to the server side:

    Code:
    // Create the destination descriptor
    TPtr8 ptr(reinterpret_cast<TUint8*>(&iParams), sizeof(iParams), sizeof(iParams));
    
    // Read data from the source to destination
    aMessage.ReadL(aMessage.Ptr0(), ptr);
    
    // Now the iParams on the server side contains garbage
    The client side handle is contained inside an object which has been allocated on the heap, so the data in the source address should remain valid until server tries to read it.

    Am I doing something wrong or have I left out something what is important for the client-server data transfer to work? I really don't know. If you notice something wrong in the code, please give me a hint. I'll appreciate any help you can provide in this problem.

    -wilse

  2. #2
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Spain
    Posts
    329
    Hi,

    I'm not 100% sure, but I'm doing a similar transfer and I've noticed some differences. (Notice that I'm running 2 process)

    First :I'm not transferring an object, just a descriptor (I've read some posts wich says it's not possible).

    Second: On the client side (handle) better declare your TPtr8 variable as a member (and be sure the data to transfer is valid till the request completes).

    Third: On the server side you cannot reference iParams (at least between two process). There is a way to get the length of the client-side descriptor aMessage.Client().GetDesLength(aMessage.Ptr0()).

    Maybe you have to allocate memory on the server-side (instead of setting a pointer).

    Good luck and I hope it helps.

    Bye,
    Toni

Posting Permissions

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