hello
i am now writing a program to BE connected by a bw4.2 application by using socket,it means that my program open the server port,the bw call my socket and send me a message that is XML format,the socket component of bw is configured to use the "utf-16le",my program run on a chinese version windoes2003 server,that use the "iso8859-1" or "gb2312" encoding.the code snippet of my program as following:
ServerSocket server = new ServerSocket(10001);
Socket client = server.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(
client.getInputStream()));
String inputLine = "";
while ((inputLine = in.readLine()) != null) {
String str=new String(inputLine.getBytes("iso8859-1"),"utf-16");
System.out.println(str);
}
and the bw send following message to my program:
<IncStatus>
<IncidentID>83700</IncidentID>
<TimeStamp>20/05/2004 13:58:34</TimeStamp>
<UserNameID>Bruce</UserNameID><WorkstationID>CLIENT1</WorkstationID>
<StatusID>3</StatusID>
</IncStatus>
but in my program,the the following is printed?
<IncStatus>?
<IncidentID>83700</IncidentID>?
<TimeStamp>20/05/2004 13:58:34</TimeStamp>?
<UserNameID>Bruce</UserNameID><WorkstationID>CLIENT1</WorkstationID>?
<StatusID>3</StatusID>?
as you can see,in the end of each line,ths sign "?" is added,and the tag "</IncStatus>" is missed.
who can help me,how can i deal with the encoding problem?
-
socket encoding problem (1 messages)
- Posted by: zhebin cong
- Posted on: May 20 2004 03:12 EDT
Threaded Messages (1)
- socket encoding problem by Mircea Crisan on May 20 2004 04:34 EDT
-
socket encoding problem[ Go to top ]
- Posted by: Mircea Crisan
- Posted on: May 20 2004 04:34 EDT
- in response to zhebin cong
Hi,
I think you should use an InputStreamReader where you can specify your charset:
InputStreamReader(InputStream in, Charset cs)
InputStreamReader(InputStream in, CharsetDecoder dec)
InputStreamReader(InputStream in, String charsetName)
Best regards, Mircea