×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    70

    Sending plain text through socket

    Hi, I'm working with sockets in Symbian c++ and i managed to make the EchoEngine example to work and now my app connects and send data through the socket. The server side has to be a Java based server, and the connection is made, and it received the data but when it is shown on a console the message has strange characters almost like it was binary and not text, how can i send plain Text through the socket so the server can read the data?

    thanks

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Sending plain text through socket

    it is propably caused by wrong character encoding, so try sending normal ASCII text from the server, or use character converters for convertign the text.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Sending plain text through socket

    If you are using "recent" S60 editions (perhaps S60 2nd FP2 and upwards), it should be possible to run your networking code in the emulator, where you can examine what you actually read from your socket using a debugger.

  4. #4
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    70

    Re: Sending plain text through socket

    if it is by wrong character encoding, how can i ensure the encoding i use in my Symbian c++ code, i write a TBuf8 into the socket, but it seems to treat it as binary data not text data, how can i set the ascii encoding in the c++ code side, the java needs to read text even UTF8 its ok, but text.

    Quote Originally Posted by symbianyucca View Post
    it is propably caused by wrong character encoding, so try sending normal ASCII text from the server, or use character converters for convertign the text.

  5. #5
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    280

    Re: Sending plain text through socket

    Through your socket you are sending binary. "Octets" as they are called in the RFCs. One of the things you can push down this binary tube is ascii text. There are variations (http://en.wikipedia.org/wiki/Plain_text or use google) but the key thing is that the code that is reading the socket is using the same format as the code writing to the socket.

    For example, one thing that might get confused is the line endings. Some systems use character 0x0d for this and some 0x0a. Bizarrely, some will even use both 0x0d 0x0a.

    The socket doesn't care what it is transmitting, it just does its best to get it there.

    Look at what you are receiving in a hex editor (or in a debugger or packet sniffer as suggested previously) and you should be able to work out what is going on.

  6. #6
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Sending plain text through socket

    ok, I misunderstood that your receiving and at phone gets it wrong. anyway, normal byte-buffer text should be ASCII encoded in symbina side.

  7. #7
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    70

    Re: Sending plain text through socket

    Hi, i've been testing my java server for the incoming data, and it always show
    HEX{[01][01][00][00][00][01][00][00][01][01][00][01][01][01][0f]}

    this is the hex value of each byte , but doesn't matter what i choose to send '000000000000000' or 'abcdefghijklmno' it sends the same data in the socket. in my server if i connect to it using putty for example and i send 'hello' it shows 'hello' the same with the strings above, i just dont get it. i connect to the server, and send a TBuf<15> , its quite simple but it doesnt work, encoding?mmm dont think so, because i append a '\n' after after the string i want to send so the java server knows it ends and it recognize the '\n' on the data it receives.

    what i intent to do is send data i shown o some labels so it has to be or numbers or letters no special characters besides '\n' if someone knows why it happens please tell me

    the code seems like

    TBuf<17> originalBuf( _L("abcdefghijklmno") );
    iEchoEngine->Write(originalBuf);

    and Write method call this

    void CEchoWrite::IssueWrite(const TDes &aText)
    // Write a data to a stream socket
    {
    TBuf<2> eolT (_L("\n"));
    // Set up buffer
    iBuffer.SetLength(0);
    iBuffer.Append(aText);
    iBuffer.Append(eolT);
    iEchoSocket->Write(iBuffer, iStatus);
    // Request timeout
    iTimer->After(iTimeOut);
    SetActive();
    iWriteStatus = ESending;
    };

  8. #8
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    280

    Re: Sending plain text through socket

    What is the definition of your Write function?
    It looks like you are passing the address or pointer of something, rather than a reference.
    Also, you are using TBuf instead of TBuf8. So, I would expect it to be wrong for that reason, but not give the values you have shown.

    If you have a log file, or can use a debugger, look at the contents of iBuffer just before you send it.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    22

    Re: Sending plain text through socket

    Huy,

    i have the same problem. my server is in c#. my symbian code is working correctly on emulator but when i installed it on n72 then it sends garbage and my server didnot receive correct data. i have used UTF8 on my server side, but it didnot work. i am using RBUF8. is there any solution...

    regards

  10. #10
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    280

    Re: Sending plain text through socket

    There's always a solution.

    You need to look at your data at each stage on its merry journey to see which bit is not as you expect.
    1. Print it to a file just before you send it.
    2. Look at it in transit using a packet sniffer.
    3. Log the raw data at the other end.

    I expect you are not sending exactly what you think, but you haven't given enough info to determine.

    Also, remember, sockets have been used once or twice successfully, so it is probably not an issue with the sockets themselves.

  11. #11
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    70

    Thumbs up Re: Sending plain text through socket

    Hi Nigel, i found the problem and you gave me clues, i found that the first method i use to call to send my data was not declared with a parameter by reference, that was all, once i change it, i went smooth on my java server, i am testing it only on the emulator not on a real device, i hope to do it in a week, i knew the socket implementation has to be compatible with any socket you write on any other language, it must the that way. now i think you're rigth that the string i was getting 00100110001111 was more like the address in memory, it was a long time ago since i did something in C/C++ but with symbian c++ im starting to remember, thanks

  12. #12
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    280

    Re: Sending plain text through socket

    Good news.
    The reason I spotted it was because I have done the same thing myself, more that once.

  13. #13
    Super Contributor
    Join Date
    Jun 2005
    Location
    Berlin
    Posts
    721

    Re: Sending plain text through socket

    void CEchoWrite::IssueWrite(const TDes &aText)
    // Write a data to a stream socket
    {
    TBuf<2> eolT (_L("\n"));
    // Set up buffer
    iBuffer.SetLength(0);
    iBuffer.Append(aText);
    iBuffer.Append(eolT);
    iEchoSocket->Write(iBuffer, iStatus);
    // Request timeout
    iTimer->After(iTimeOut);
    SetActive();
    iWriteStatus = ESending;
    };
    I think, you should use .Copy() than .Append(). Because the iBuffer must be TDes8, and the parameter aText is a 16Bit.

    something like
    Code:
    TBuf8<2> eolT (_L8("\n"));
    iBuffer.Zero();
    iBuffer.Copy(aText);
    iBuffer.Append(eolT);
    ....

  14. #14
    Registered User
    Join Date
    Nov 2007
    Posts
    22

    Re: Sending plain text through socket

    Huy,

    thanks for your response. i am using following code to send my string


    void CMobiMessengerContainerView::SignIn()
    {
    GlobalData* aGlobalData = GetGlobalData();
    TBuf<20> aTempBuf(20);
    RBuf8 aQuery;
    aQuery.CleanupClosePushL();
    aQuery.CreateL(100);

    aQuery.Append(SI_Catagory_Code());
    aQuery.Append(Entity_Code());

    iTextBoxID->GetText(aTempBuf);
    aGlobalData->iSignInUser.Create(aTempBuf.Length());
    aGlobalData->iSignInUser.Append(aTempBuf);
    aQuery.Append(aTempBuf);
    aQuery.Append(Entity_Code());

    aTempBuf.Zero();
    iSecretPassword->GetText(aTempBuf);
    aQuery.Append(aTempBuf);
    aQuery.Append(Entity_Code());

    aQuery.Append(_L("Online"));
    aQuery.Append(Entity_Code());

    aGlobalData->iSocketEngine->WriteL((TDesC8)aQuery);

    CleanupStack::PopAndDestroy();
    }

    const TDesC8& Entity_Code()
    {
    _LIT8(toReturn,"!#!");
    return toReturn;
    }

    const TDesC8& SI_Catagory_Code()
    {
    _LIT8(toReturn,"#*SI");
    return toReturn;
    }

  15. #15
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    280

    Re: Sending plain text through socket

    aGlobalData->iSocketEngine->WriteL((TDesC8)aQuery);
    looks wrong. What is the definition of WriteL? It should be passing by reference.
    http://library.thinkquest.org/C01115...ual.php?tid=51
    http://library.thinkquest.org/C01115...ual.php?tid=52
    Print "aQuery" and print the value you receive in "WriteL". I expect they are different.

    Also, if you worry about the naming convention, the "a" in "aQuery" means it was passed as an argument. http://developer.symbian.com/wiki/pa...ion?pageId=530

Similar Threads

  1. simultaneous sending and receiving on socket
    By santosh shetty in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2008-02-07, 15:34
  2. Problem sending data over socket on 6680
    By jonesydotcom in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2007-02-21, 14:06
  3. sending sms using socket in 3rd edition..?
    By sumit_rusia in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-02-15, 13:24
  4. Sending Text over bluetooth
    By Amilael in forum Symbian
    Replies: 1
    Last Post: 2006-08-11, 14:11
  5. Urgent - problems sending SMS text from PC
    By Nokia_Archive in forum General Messaging
    Replies: 1
    Last Post: 2002-05-23, 14:56

Posting Permissions

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