Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Asif Kadiwala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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
  • 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???
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic