Archived

This forum has been archived. Please start a new discussion on GitHub.

ICE client encoding GBK error

I use ice java client to get chinese string from Ice c++ server,but it show "?"all.

Ice Server:
Linux 2.4.30 + gcc 3.3.4 + Ice-3.0 + ISO-8859-1

Ice Client:
Windows 2000 + Jdk 1.5 + IceJ-2.1.2 + GBK

I solved this problem by calling iconv in c ;

this function help me transfer gbk to utf8 , then java receive the string in right coding format.

But my question is:
if I do not transfer gbk to utf8 in c, how can java receive the string in right coding format?

May you provide some advice . Thank u so much!!

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Strings should always be encoded with UTF-8 on the wire. So your application should provide UTF-8 strings to the Ice runtime and should expect receiving UTF-8 strings from servers. However, with Ice for C++, you can install with the Ice communicator an automatic converter to automatically convert your strings to and from UTF-8.

    See the demo/Ice/converter demo from your Ice distribution for an example and the section "30.21 C++ String Conversion" for more information.

    Cheers,
    Benoit.
  • my question is that...
    benoit wrote: »
    Hi,

    Strings should always be encoded with UTF-8 on the wire. So your application should provide UTF-8 strings to the Ice runtime and should expect receiving UTF-8 strings from servers. However, with Ice for C++, you can install with the Ice communicator an automatic converter to automatically convert your strings to and from UTF-8.

    See the demo/Ice/converter demo from your Ice distribution for an example and the section "30.21 C++ String Conversion" for more information.

    Cheers,
    Benoit.

    hi Benoit. Thank u for your advice

    I have try to provide UTF-8 strings,and java can receive the string in right coding format.

    But my question is:
    For several reason I do not want to change my c source (it provide GBK strings , it do not transfer gbk to utf8 in c),
    how can java receive the string in right coding format?

    I guess if I could modify the ice.jar source(BasicStream.class) to let java receive the string wIth GBK? or any other way?

    May you provide some advice for my question ?

    Thanks a lot

    Cheers,

    Koko.
  • benoit
    benoit Rennes, France
    But my question is:
    For several reason I do not want to change my c source (it provide GBK strings , it do not transfer gbk to utf8 in c),

    You can continue using GBK in your source if you install a converter with the Ice communicator, this is really the easiest and best solution. Or can't you even modify the source where the communicator is initialized (that's where you should setup the string converter)?
    how can java receive the string in right coding format?

    I guess if I could modify the ice.jar source(BasicStream.class) to let java receive the string wIth GBK? or any other way?

    May you provide some advice for my question ?

    You can modify the Ice source since we provide it but I don't recommend you to do it, we won't support such a configuration.

    Cheers,
    Benoit.
  • How can I make change in the java client to let work right.
    benoit wrote: »
    You can continue using GBK in your source if you install a converter with the Ice communicator, this is really the easiest and best solution. Or can't you even modify the source where the communicator is initialized (that's where you should setup the string converter)?

    You mean I should change my source in server?
    in my project ,client must receive the string in GBK.
    Except the java client,other clients should use the string in GBK.
    How can I make change in the java client to let work right.
  • Ice requires that all strings are transmitted as UTF-8. If you don't do that, then you will run into problems with other language mappings as well, such as Ice for Python.

    You could certainly hack your Ice for Java client so that it converts GBK to UTF-8, but we do not provide any support for this. As Benoit says, the correct solution is to convert GBK to UTF-8 at your C++ server, using an appropriate implementation of our string converter.
  • i got it

    Thanks guys.
  • bernard
    bernard Jupiter, FL
    I'd also recommend to read my article "Ice and Character Encoding" in issue 16 of the Connections.

    Cheers,
    Bernard
  • bernard wrote: »
    I'd also recommend to read my article "Ice and Character Encoding" in issue 16 of the Connections.

    Cheers,
    Bernard

    I see.

    Cheers,
    Koko
  • it seems that every chinese have this problem...:D

    infact, use stringconvert, you can resolve this problem gracefully.:D