Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 12-14-2005
richardma richardma is offline
Registered User
 
Name: richard
Organization: qq
Project: wap
 
Join Date: Dec 2005
Posts: 31
Send a message via ICQ to richardma Send a message via MSN to richardma
-->
Encoding Problem about Chinese, client compiled by Java, server compiled by C++

a project server compiled by C++ and client compiled by java for display, but a problem comes when Chinese display.
when I compiled client by C++, the Chinese display is normal, but when I compiled client by java, the Chinese display isn't normal, that's disorder.
Now I solved it by update the source, under directory "src/IceInternal".
If there others way solve it, such as update config etc.??
__________________
Wireless Support Platform
---------------------------------------------
Yanbo Ma
Central University for Nationality, P.R.China
http://www.cun.edu.cn
yanboma_bj@yahoo.com.cn
---------------------------------------------
Reply With Quote
  #2 (permalink)  
Old 12-15-2005
benoit's Avatar
benoit benoit is offline
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,540
Hello,

I'm afraid we can't help you without more information about your problem. Could you post the sample source code that demonstrates the problem? How do you print the strings in the C++ and Java client for instance?

Also, what did you change in src/IceInternal to get it to work?

Benoit.
Reply With Quote
  #3 (permalink)  
Old 12-15-2005
richardma richardma is offline
Registered User
 
Name: richard
Organization: qq
Project: wap
 
Join Date: Dec 2005
Posts: 31
Send a message via ICQ to richardma Send a message via MSN to richardma
-->
my code as follows:

ice definition:
#ifndef HELLO_ICE
#define HELLO_ICE

module Demo
{

interface Hello
{
nonmutating void sayHello();
};

};

#endif



C++ implement server:
HelloI::sayHello(const Ice::Current&) const
{
cout << "Hello World!哈哈哈哈哈哈哈" << endl;
}

when java client call 'sayHello' on windows the result is:
Hello World!?????????


The source I update is:
the directory: IceJ-2.1.2/src/IceInternal
the file :BasicStream.java
I note the 'UTF8' encode is the main modification.
the result of differ as follow:
diff -r IceJ-2.1.2.1/src/IceInternal/BasicStream.java IceJ-2.1.2/src/IceInternal/BasicStream.java
1038c1038
< // try
---
> try
1040,1041c1040
< //byte[] arr = v.getBytes("UTF8");
< byte[] arr = v.getBytes();
---
> byte[] arr = v.getBytes("UTF8");
1046,1049c1045,1048
< // catch(java.io.UnsupportedEncodingException ex)
< // {
< // assert(false);
< // }
---
> catch(java.io.UnsupportedEncodingException ex)
> {
> assert(false);
> }
1121,1122c1120
< //return new String(_stringBytes, 0, len, "UTF8");
< return new String(_stringBytes, 0, len);
---
> return new String(_stringBytes, 0, len, "UTF8");
1131c1129
< /* catch(java.io.UnsupportedEncodingException ex)
---
> catch(java.io.UnsupportedEncodingException ex)
1136c1134
< */ catch(java.nio.BufferUnderflowException ex)
---
> catch(java.nio.BufferUnderflowException ex)
__________________
Wireless Support Platform
---------------------------------------------
Yanbo Ma
Central University for Nationality, P.R.China
http://www.cun.edu.cn
yanboma_bj@yahoo.com.cn
---------------------------------------------
Reply With Quote
  #4 (permalink)  
Old 12-15-2005
benoit's Avatar
benoit benoit is offline
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,540
Is this really the code you're using? The code you posted doesn't receive a string over the wire, it just prints a string on the standard error output so I don't see how invoking the sayHello() method would print different strings if invoked from a C++ client or Java client.

It's also not quite clear from the diff output what are the changes you made. Could you just post your BasicStream.java file with your modifications as an attachment?

Benoit.
Reply With Quote
  #5 (permalink)  
Old 12-15-2005
richardma richardma is offline
Registered User
 
Name: richard
Organization: qq
Project: wap
 
Join Date: Dec 2005
Posts: 31
Send a message via ICQ to richardma Send a message via MSN to richardma
-->
Because the code I using is much, I didn't paste it. I only want to explain the phenomenon that display the Chinese through the code as above, it isn't the code I using.

the BasicStream.java I modified as follow:
public void
writeString(String v)
{
if(v == null)
{
writeSize(0);
}
else
{
final int len = v.length();
if(len > 0)
{
// try
{
//byte[] arr = v.getBytes("UTF8");
byte[] arr = v.getBytes();
writeSize(arr.length);
expand(arr.length);
_buf.put(arr);
}
// catch(java.io.UnsupportedEncodingException ex)
// {
// assert(false);
// }
}
else
{
writeSize(0);
}
}
}

public void
writeStringSeq(String[] v)
{
if(v == null)
{
writeSize(0);
}
else
{
writeSize(v.length);
for(int i = 0; i < v.length; i++)
{
writeString(v[i]);
}
}
}

public String
readString()
{
final int len = readSize();

if(len == 0)
{
return "";
}
else
{
try
{
//
// We reuse the _stringBytes array to avoid creating
// excessive garbage
//
if(_stringBytes == null || len > _stringBytes.length)
{
_stringBytes = new byte[len];
_stringChars = new char[len];
}
_buf.get(_stringBytes, 0, len);

//
// It's more efficient to construct a string using a
// character array instead of a byte array, because
// byte arrays require conversion.
//
for(int i = 0; i < len; i++)
{
if(_stringBytes[i] < 0)
{
//
// Multi-byte character found - we must use
// conversion.
//
// TODO: If the string contains garbage bytes
// that won't correctly decode as UTF, the
// behavior of this constructor is
// undefined. It would be better to explicitly
// decode using
// java.nio.charset.CharsetDecoder and to
// throw MarshalException if the string won't
// decode.
//
//return new String(_stringBytes, 0, len, "UTF8");
return new String(_stringBytes, 0, len);
}
else
{
_stringChars[i] = (char)_stringBytes[i];
}
}
return new String(_stringChars, 0, len);
}
/* catch(java.io.UnsupportedEncodingException ex)
{
assert(false);
return "";
}
*/ catch(java.nio.BufferUnderflowException ex)
{
throw new Ice.UnmarshalOutOfBoundsException();
}
}
}
__________________
Wireless Support Platform
---------------------------------------------
Yanbo Ma
Central University for Nationality, P.R.China
http://www.cun.edu.cn
yanboma_bj@yahoo.com.cn
---------------------------------------------
Reply With Quote
  #6 (permalink)  
Old 12-15-2005
bernard's Avatar
bernard bernard is online now
ZeroC Staff
 
Name: Bernard Normier
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Palm Beach Gardens, FL
Posts: 816
Since the string displayed by your C++ program is not transmitted by Ice, Ice is not involved. And your change to the Ice source code does not help.

In C++, to display wide-strings, you should use wcout, e.g.:
wcout << L"Hello World [chinese characters]" << endl;

Cheers,
Bernard
__________________
Bernard Normier
ZeroC, Inc.
Reply With Quote
  #7 (permalink)  
Old 12-21-2005
lifejoy lifejoy is offline
Registered User
 
Name: lifejoy
Organization: klmt
Project: 1919&secondplat
 
Join Date: Nov 2005
Posts: 6
Re

Quote:
Originally Posted by bernard
Since the string displayed by your C++ program is not transmitted by Ice, Ice is not involved. And your change to the Ice source code does not help.

In C++, to display wide-strings, you should use wcout, e.g.:
wcout << L"Hello World [chinese characters]" << endl;

Cheers,
Bernard
In C++ Service you should encoding you local text to UTF-8, then you can receive correct message in java client ,so you can encoding you message text in java with GB2312! good luck!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pre-Compiled Headers mario Help Center 9 11-10-2005 04:22 AM
encoding error when Ice java client get string from Ice c++ server casper Help Center 1 09-16-2005 04:01 AM
Ice and native compiled Java (GJC) taweili Help Center 0 02-02-2004 09:20 PM
Can Ice be compiled with gcc 2.95? jukvaini Help Center 5 04-07-2003 05:18 AM


All times are GMT -4. The time now is 10:17 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.