Mutilanguage problem

in Help Center
My demo is below :
Printer.ice
...
nonmutating string testMutiLang(string s);
...
PrinterI.cpp
string PrinterI::testMutiLang(const string & s, const Ice::Current&) const
{
cout << "receive " << s << endl;
string sRet;
sRet="Iam’†•¶chinese" ; // middle part is represent chinese language in my real code
return sRet ;
....
the client code in c
string sRet = twoway->testMutiLang(sOut);
cout << "client get from server : " << sRet << endl;
when run I get the right output
the client in java
String sRet = twoway.testMutiLang(sOut);
System.out.println("client get from server ") ;
System.out.println(" ¥•s¥’†•¶ ") ;
System.out.println( sRet );
when run I get Iam????chinese
by the way I use linux slackware gcc 3.2.3 jdk 1.4.2
and if use java to output chinese , is right .
env set LC_ALL=zh_CN
how can I resolve this problem?
expect your help . thx.
Printer.ice
...
nonmutating string testMutiLang(string s);
...
PrinterI.cpp
string PrinterI::testMutiLang(const string & s, const Ice::Current&) const
{
cout << "receive " << s << endl;
string sRet;
sRet="Iam’†•¶chinese" ; // middle part is represent chinese language in my real code
return sRet ;
....
the client code in c
string sRet = twoway->testMutiLang(sOut);
cout << "client get from server : " << sRet << endl;
when run I get the right output
the client in java
String sRet = twoway.testMutiLang(sOut);
System.out.println("client get from server ") ;
System.out.println(" ¥•s¥’†•¶ ") ;
System.out.println( sRet );
when run I get Iam????chinese
by the way I use linux slackware gcc 3.2.3 jdk 1.4.2
and if use java to output chinese , is right .
env set LC_ALL=zh_CN
how can I resolve this problem?
expect your help . thx.
0
Comments
Thank marc , I read some articles about java encoding , then I try test my program again , and problem still exist . This time I upload the whole test program zipped in tar.gz .
My Action in turn is :
1 - icepacknode --Ice.Config=config --warn
2 - ./client
this step , I get the right string return by PrinterI::testMultiLang
and at the same time server side get right input :
receive string is : Äã
3 - java -cp ./classes/:/usr/local/data/icej/lib/Ice.jar M4.client
this step I can not get the right string returned by PrinterI::testMultiLang and at the same time
client side get
char of sRet is
0 - fffd
1 - fffd
byte of sRet is
0 - 3f
1 - 3f
server side get input string in unicode
src line : cout << " -" << i << " - "<< hex << (int)ws << endl ;
work and output : -0 - 4f60
by the way :
the code in PrinterI.cpp
....
char sTmp[3] ;
memset(sTmp,0,sizeof(sTmp)) ;
sTmp[0] = 0xc4 ;
sTmp[1] = 0xe3 ;
sReturnString = sTmp ; //here return chinese string
....
and the code in cient.java
byte b[]={(byte)'\u00c4',(byte)'\u00e3'};
String strInput ="" ;
try {
strInput = new String (b,"GBK") ;
System.out.print( " strInput composed" ) ;
System.out.print( strInput ) ;
System.out.print( " \r\n " ) ;
}
catch ( java.io.UnsupportedEncodingException ex )
{
System.out.println("catch UnsupportedEncodingException") ;
}
are both equal to
sReturnString = "Äã" ; // string composed by one chinese letter
May you see the source code and provide some advice .
thx .
Try this instead:
strInput = new String(b, 0, 2, "UTF8");
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.
very appreciate your answers , and ICE is a good and useful thing .