Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2005

Tip: Looking for answers? Try searching our database.

Write Socket Output with extend ASCII

Thread view: 
pcouas - 11 Aug 2005 18:04 GMT
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.getOutputSt­ream(),true);
     temp=new String("");
     temp=temp.concat(String.valueO­f((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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.