×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    3

    Getting an int over a socket

    Hello. I've been trying for several hours now a realy simple action: Getting an int together with an unsigned char over a proxy

    This works:
    Code:
    _LIT8(KData, "UPD 46012311 ");
    TBufC8<32> str(KData);
    iSocketsEngine->WriteL(str);
    My Question: How the hell am I gonna get an integer in it?
    I want sometghing like
    Code:
    TInt cell(CellId); // CellId is just a plain int
    _LIT8(KData, "UPD 46012311 "+cell);
    TBufC8<32> str();
    iSocketsEngine->WriteL(str);
    But that isn't gonna work

    I've tried:
    - sprintf (implicit call of sprintf)
    - for loop with a char[] (warning: aggregate has a partly bracketed initializer) (?)

    How can i do it??
    Last edited by vanthof; 2005-01-17 at 12:39.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    64
    Do you simply want to append to the string buffer? Then try:

    TInt cell(CellId);
    _LIT8(KData, "UPD 46012311 ");
    TBufC8<32> str(KData);
    str.AppendNum(CellId);
    iSocketsEngine->WriteL(str);

    Alternatively you could create your own external data representation format, marshal all in a descriptor buffer, blow out to the socket and rebuild it on the other side...

    Cheers,
    Stevie

  3. #3
    Registered User
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    3
    Yeah, that's what I also figured out.

    But since TBufC8 is a NON-modifiable descriptor (http://www.cs.tut.fi/~mobo/Symbianv6...ufC8Class.html) you can't change anything once it's inside there...

    The append actions has to be befor the TBufC8 definition. And since _LIT8 onl is declareable if you put the actual string in the definiton (don't try a var, you'll get errors, even it's a unsigned char[]) I don't know where to search anymore..

    Begin to see my problem?

    [edit]
    I changed the TBufC8 into a TBuf8.. It compiles fine now with the code you mentioned. I'm gonna test it now irl.. I'll ket you know in about 15 mins.
    [/edit]
    Last edited by vanthof; 2005-01-17 at 13:10.

  4. #4
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    153
    Hi, i think this will work,


    _LIT8(KData, "UPD 46012311 %d");

    TInt cell(CellId);

    TBuf8<10> iBuf;

    iBuf.Format(KData,cell);

    TBufC8<10> iNew(iBuf)

    iSocketsEngine->WriteL(iNew);

    Cheers,
    Sunil

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    64
    I changed the TBufC8 into a TBuf8.. It compiles fine now with the code you mentioned. I'm gonna test it now irl.. I'll ket you know in about 15 mins.
    [/edit] [/B]
    Ah, ja, sorry for that. It certainly must read TBuf8<..> and not TBufC8<..>.

    Cheers,
    Stevie

  6. #6
    Registered User
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    3
    Thx for your replies. It all works fine now.. The deadline is tomorrow.. You have no idea how greatfull I am.. THX!!

    Working code:

    Code:
    _LIT8(KData, "UPD 46012311 ");
    TBuf8<32> str(KData);
    str.AppendNum(CellId);
    iSocketsEngine->WriteL(str);
    9 hours of trying solved with backspacing one C (TBuf8 instead of TBufC8)

Posting Permissions

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