×

Discussion Board

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

    How to read remote device directories' names (using socket)

    Hello,

    I am pretty new to Symbian and I would highly appreciate if you guys could get me out of this. I have been doing a bit of research but don't know how to start it.

    I have an application on two different devices (same application) and the basic idea is that I want to see directory names of device A on device B on lets say in C drive or file list in hard coded folder 'foo' which is in 'c\data\foo'. The socket part is done already i.e. the socket is established between the two devices. The thing that I have understood so far is that I have to use Serialization and DeSerialization i.e. ExternalizeL() and InternalizeL(). But I have no idea how should I start with it. A push or pointer (or more) would be highly appreciated in getting me out of this.

    I went throught this http://discussion.forum.nokia.com/fo...d.php?t=101769 and other posts but I don't know how much does it help my case.

    And Would I need to Build and Parse a message containing the data or Externalize and Internalize will do that for me?

    Thanks.

    Garry
    Last edited by garrygar; 2009-01-14 at 16:33.

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

    Re: How to read remote device directories' names (using socket)

    Since the combined length of - say - filenames in a directory can vary a lot, serialization is a good idea.
    On the sender side you could make use of an RBufWriteStream with a CBufFlat. After serialization, you know the length, that is what you should send to the receiver side first:
    Code:
    CBufFlat *buf=CBufFlat::NewL(10);
    CleanupStack::PushL(buf);
    RBufWriteStream stream;
    stream.Open(*buf);
    stream.PushL();
    // serialize your data here
    stream.CommitL();
    CleanupStack::PopAndDestroy(); // stream
    
    TPckgBuf<TInt> size; // TPckgBuf is a 8-bit descriptor, containing an instance of the type specified as the template argument
    size()=buf->Size();  // TPckgBuf::operator() provides access to the contained object
    
    TRequestStatus stat;
    socket.Write(stat,size);
    User::WaitForRequest(stat);
    User::LeaveIfError(stat);
    
    socket.Write(stat,buf->Ptr());
    User::WaitForRequest(stat);
    User::LeaveIfError(stat);
    
    CleanupStack::PopAndDestroy(); // buf
    Of course this code is nasty, because using User::WaitForRequest blocks your whole application. So in reality and active object should be used, but for testing purposes the code actually works, and it is more readable this way.

    On the receiver side you get "size" first, then you should read exactly the same amount of data from the socket. It is tricky a bit, because creating a descriptor of specified size in runtime is a bit tricky:
    Code:
    TPckgBuf<TInt> size;
    
    TRequestStatus stat;
    socket.Read(stat,size);
    User::WaitForRequest(stat);
    User::LeaveIfError(stat);
    
    HBufC8 *buf=HBufC8::NewLC(size()); // this line allocates a descriptor which can contain the specified size, but it can be larger in fact
    TPtr8 ptr( const_cast<TUint8*>(&(*buf)[0]), size()); // there are a number of equally ugly approaches you could choose from
    socket.Read(ptr,size);
    User::WaitForRequest(stat);
    User::LeaveIfError(stat);
    
    RDesReadStream stream;
    stream.Open(*buf);
    stream.PushL();
    // deserialize your data
    CleanupStack::PopAndDestroy(2); // stream, buf
    Or an alternative would be RecvOneOrMore-ing in a loop, and collecting the data (in a CBufFlat for example) until the specified length has been reached.

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

    Re: How to read remote device directories' names (using socket)

    Hi,

    Thanks for the detailed instructions. Yes you are right that the filename varies. But if I am able to read one hard-coded file name or directory name then I would be on track and can (hopefully) extend it from there on.

    Anyway, in the solution you have provided, would I need to build (sender side )and parse (receiver side) the data i.e. the file name or will serialize and deserialize work the same thing for me? Second is there any Externalize/Internalize functions available in some API in S60/Symbian or do I have to implement my own serialize/deserialize functions? If I have to implement my own, could you give some hint/clue/idea/sample code?

    Thanks

    Garry

Similar Threads

  1. AT Commands (was Re: Ask the Expert: Remote Device Access)
    By guioguio in forum Wired and Wireless interfaces (Closed)
    Replies: 7
    Last Post: 2009-10-07, 07:59
  2. dealing with manual removal of pairing from remote device
    By andradf in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-07-05, 06:43
  3. Read from socket never blocking
    By barnabyg in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2006-07-06, 13:45
  4. Infrared socket connection between Symbian device and Windows
    By vespe in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2003-10-10, 16:50
  5. TCP socket connection between Symbian device and Windows
    By raghucp in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2003-09-15, 10:15

Posting Permissions

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