×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Aug 2007
    Posts
    55

    Send string data from symbian to .net

    Hi!

    I need to send string data with special characters from a Symbian S60 3rd Ed. phone to a server running on a Windows platform. The server is written in C++/CLI and I need the string data as a managed string on the server. I currently convert the string to UTF8 on the phone and send it, like this:

    Code:
    HBufC* heapbuffer = HBufC::NewLC(aMessage.Length());
    heapbuffer->Des().Copy( aMessage );
    HBufC8* heapbuffer8 = HBufC8::NewLC(aMessage.Length());
    TPtr8 tmpBuf8(heapbuffer8->Des());
    CnvUtfConverter::ConvertFromUnicodeToUtf8(tmpBuf8,*heapbuffer);
    
    iSocket->Write(*heapbuffer8, iStatus);
    The descriptor aMessage of course contains the message to be sent. Then, on the server I convert it back using the following code:

    Code:
    Encoding^ enc = Encoding::UTF8;
    int socket = (int)param, bytesReceived, selectret;
    char cbuf[BUFFER_MAX_LENGHT];
    bytesReceived = recv(socket, cbuf, BUFFER_MAX_LENGHT, 0);
    
    cbuf[bytesReceived] = '\0';
    array<Byte>^ receivedBytes = gcnew array<Byte>(bytesReceived + 1);
    for(int i = 0; i < (bytesReceived + 1); i++)
        receivedBytes[i] = cbuf[i];
    System::String^ managedBuffer = enc->GetString(receivedBytes);
    This works, most of the time. However, sometimes the data seems to be sent incorrectly. For example, I had big problems sending over a string containing the number 26. When appending this number to another string to be passed as an SQL statement to a function, the server crashed. However, if I first convert the string to a number containing the number 26, and the convert it back to a string it works.

    Any idea what is wrong with my string conversion? In the end I am simple trying to send data possibly containing special chars to a server running on .NET. How should I do that?

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

    Re: Send string data from symbian to .net

    maybe you should base64 the data when sending it over, it should eliminate any problems with binary values of the string items at least.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    41

    Re: Send string data from symbian to .net

    It worked for me. I had to implement xml-rpc communications between .net server code (c#) and s60 phone, xml part was regular ascii, binary data in the message was base64-ed. Works like a dream.

Similar Threads

  1. send data to phone from internet, ideas?
    By acode in forum Symbian
    Replies: 3
    Last Post: 2007-12-30, 13:49
  2. unable to send a string to a data using write function.
    By Mohan Kumar in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2007-03-01, 15:02
  3. Replies: 2
    Last Post: 2006-10-04, 19:41
  4. how to send data at connection request phase over RSoceket using TCP protocol
    By madsum in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-10-04, 09:59

Posting Permissions

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