Meaningless Drivel is fun!*
The moose likes Sockets and Internet Protocols and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark ""MISSING BYTE ORDER MARK" exception during receiving messege through socket" Watch ""MISSING BYTE ORDER MARK" exception during receiving messege through socket" New topic
Author

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

Asif Kadiwala
Greenhorn

Joined: Jun 10, 2008
Posts: 17
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
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
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.


Ping & DNS - my free Android networking tools app
Asif Kadiwala
Greenhorn

Joined: Jun 10, 2008
Posts: 17
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

Joined: May 27, 2008
Posts: 225

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "MISSING BYTE ORDER MARK" exception during receiving messege through socket