Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-22-2008, 01:48 PM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
writting extended ascii chars on socket........or Endianness Issue......??
Dear All,

This is small problem i am facing while writting a some extended ascii characters( range between 128 -160 vendor dependent representation of characters) on socket.

When i write them as HEX 80 the other side program which is in C++ and on unix m/c read it as HEX 3F
The unix side program is in C++. Conversion is like this

128 Dec 80 Hex 10000000

63 Dec 3F Hex 00111111

below code I am using..
Code:
String Data =new String ((char)128); InetSocketAddress sockAddr = new InetSocketAddress("1.1.1.1",50071); Socket socket = new Socket(); socket.connect(sockAddr,100000); BufferedReader rd1 = new BufferedReader(new InputStreamReader(socket.getInputStream())); String[] codePages = {"CP437", "CP737", "CP775", "CP850", "CP852", "CP855", "CP857", "CP860", "CP861", "CP862", "CP863", "CP864", "CP865", "CP866", "CP869", "CP874", "CP856","CP858","CP868","CP870"}; BufferedWriter wr1 = new BufferedWriter(new OutputStreamWriter (socket.getOutputStream(),codepage[0])); wr1.write(data); wr1.flush();

As I searched java is always Big Endian and other side program might be Little Endian ByteOrder may be different.So this might be the reason .

Or the issue is related to character set issue i.e code pages supported by platform.

But i tried with all above character sets and its still not giving proper result..

Does Java NIO will solve the problem but never worked with it ??

Does Stream or Writer classes has to do something with it...???

Thanx ....All...

.. Sachin ..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-22-2008, 03:41 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
Writers often do char conversions correctly, but do not address the endian issue. You are mixing Streams and Writers, that cannot be good. Possibly we are getting byte to char conversions rather than endianess being at issue.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-22-2008, 04:50 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
String Data =new String ((char)128);
How do you compile this?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-22-2008, 06:03 PM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
sorry its like
Code:
char c[]={(char)128,(char)129,....}; String data=new String(c);
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-22-2008, 06:05 PM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
Hi Nicholas,,
Can you plz elaborate on the same or
Where I am actually doing mistake....

Thanx...
Sachin
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-22-2008, 08:12 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
The 3F is a ?. Different encodings use that when they do NOT have a valid char to use.
Here's a quick demo program that shows how different encodings generate different results:
Code:
// Writing chars > ASCII or ??? import java.io.*; public class Test8 { public static void main(String[] args) { String data =new String("\u00a7\u0080"); // \u0080 written to file as 3F (?) with encoding CP437 // \u0080 written to file as 3F (?) with encoding CP1254 // \u0080 written to file as 80 with encoding 8859_1 System.out.println("data=" + data); //data=§? String[] codePages = {// "8859_1", "CP1254", //NCR added these "CP437", "CP737", "CP775", "CP850", "CP852", "CP855", "CP857", "CP860", "CP861", "CP862", "CP863", "CP864", "CP865", "CP866", "CP869", "CP874", "CP856", "CP858", "CP868", "CP870" }; try { FileOutputStream fos = new FileOutputStream("Text8Output.txt"); // write to file BufferedWriter wr1 = new BufferedWriter( new OutputStreamWriter(fos, codePages[0])); //java.io.UnsupportedEncodingException: Cp437 with 1.4.2 OK with 1.6.0 wr1.write(data); wr1.flush(); wr1.close(); }catch(Exception x) { x.printStackTrace(); } } // end main() } // end class
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-23-2008, 08:38 AM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
Hi Norm,,

I tried all char sets..or Code pages around(130)....
But still the same problem persist....
And tried with all unicodes also...

As i tried OutputStream also and not writer...

Does byteorder or Endianness is causing this???

As my client socket is on java and server is on C++.....

Thanx...
Sachin...
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-23-2008, 03:52 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Did you try 8859_1? It works in the sample code I posted.
If the char maps/encodes to a single byte, the Endianness is not relevant. one byte is one byte.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 09-23-2008, 04:20 PM
Member
 
Join Date: Aug 2008
Posts: 9
sachinj13 is on a distinguished road
Thanx Norm,,,

Its workin now....

Thank u very much.....

Sachin......
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating ASCII character set JavaForums Java Blogs 2 09-15-2008 10:44 PM
ASCII to EBCDIC conversion satish kumar Advanced Java 1 08-13-2008 03:59 PM
Can we append more than 255 chars to <a href>?? freddieMaize Advanced Java 22 07-18-2008 06:04 PM
Getting ASCII codes of character gapper New To Java 1 02-02-2008 11:42 AM
abstract extended and hiding variable?? Ace_Of_John New To Java 5 12-23-2007 04:46 PM


All times are GMT +3. The time now is 08:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org