Hi,
I want send datas by socket, but my ASCII value upper than 128 are
truncated, do you have an idea ?
I could not use JDK 1.4 or higher, because this customer has an AIX
4.3.3 .
Thanks
Philippe
Socket socket = new Socket(server, port);
PrintWriter output = new
PrintWriter(socket.getOutputStream(),true);
temp=new String("");
temp=temp.concat(String.valueOf((char)0x200)); //Pb Here
temp=temp.concat(query); //OK
output.print(temp);
output.print((char)0x200); // Pb Here
output.flush();
Cantankerous Old Git - 11 Aug 2005 19:49 GMT
> Hi,
>
[quoted text clipped - 15 lines]
> output.print((char)0x200); // Pb Here
> output.flush();
PrintWriter uses the platform's defaut character encoding when
converting from text to byte stream. From this code snippet,
there is no clue whatsoever as to what character encoding scheme
the network bytes will be in - on an AS/400 it may well come out
in EBCDIC.
I suggest that you use an OutputStream Writer, and specify the
character encoding scheme in the constructor. You can wrap this
in a PrintWriter if needed. Using a BufferedOutputStream round
the OutputStream may improve performance, while you're at it.
e.g.:
Socket socket = new Socket(server, port);
OutputStream os = Socket.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
OutputStreamWriter osw = new OutputStreamWriter(bos,
"ISO8859_1");
PrintWriter output = new PrintWriter(osw);
If you specify ASCII as the output bytestream format, it will (as
it should) convert all character codes above 127 to '?'. There is
no such standard as "extended ASCII". You need to be specific as
to the byte coding used. This may involve asking the pre-existing
application you're trying to talk to what encoding it expects.
The Cog
Roedy Green - 12 Aug 2005 04:49 GMT
>PrintWriter uses the platform's defaut character encoding when
>converting from text to byte stream.
// how to determine the default encoding
// in JDK 1.5+
String defaultEncodingName = Charset.defaultCharset().name();
// in JDK 1.4, defaultEncoding will typically be Cp1252
String defaultEncoding = System.getProperty( "file.encoding" );
// canonicalName will be typically be windows-1252
String canonicalName = Charset.forName( defaultEncoding ).name();
pcouas - 12 Aug 2005 08:07 GMT
Thanks, that's good
Philippe
PS
I could not use JDK 1.4 and JDK 1.5, because customer has an AIX 4.3.3
with only JDK 1.3.1
Roedy Green - 12 Aug 2005 04:21 GMT
>I want send datas by socket, but my ASCII value upper than 128 are
>truncated, do you have an idea ?
Are you sending bytes or chars? What is translating your chars to
bytes and what encoding is it using?
See http://mindprod.com/applets/fileio.html
alse
http://mindprod.com/jgloss/encoding.html