• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"MISSING BYTE ORDER MARK" exception during receiving messege through socket

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,


I am using Java application as Socket server and C# application as Socket client. Server is listening at port 1800.

from the C# client when I m sending a String with UNicode encoding to java server then I am getting follwing error during convertting BufferedReader to String using readLine() methos : sun.io.MalformedInputException: Missing byte-order mark

SO my doubt is that, Is there any way to add Byte Order at C# client so that we can receive cleanly. In the ASCII case I can receive cleanly.

Follwing is the code snippet at the server ,

ServerSocket ss=new ServerSocket(1800);
Socket s=ss.accept();
System.out.println("Client Accepted");
BufferedReader br=new BufferedReader(new
InputStreamReader(s.getInputStream(),"UNICODE"));

String s1 = br.readLine(); // This line throws exception


Please help me ASAP. Thanks in advance
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure. A byte order mark is just two additional bytes at the beginnings of the file: http://en.wikipedia.org/wiki/Byte_Order_Mark It should be no problem to send those before the file contents are sent.
 
Asif Kadiwala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I had already tried with that, I had inserted "FEFF" at the start of the message but still getting same exception.

any idea???
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean the four characters "FEFF", or the single character '\uFEFF'? You can get the correct bytes from System.Text.Encoding.Unicode.GetPreamble().

In any case, data coming from C# is likely to be little-endian, so you could try using "UTF-16LE" on the Java side instead; or you could try using UTF-8 on both ends, which doesn't have a byte order and doesn't require a Byte Order Mark.
 
This tiny ad is wafer thin:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic