用Indy组件中的TIdTCPClient组件向java的服务器端传递文本,一直有乱码问题。今天解决了。
我的开发环境是c++ builder 2009,indy 10。
c++的客户端程序代码大致如下:
if(!IdTCPClient1->Connected()){
IdTCPClient1->Connect();
}
IdTCPClient1->IOHandler->WriteLn(”汉字123abcd”,enUTF8);
IdTCPClient1->Disconnect();
java服务端的代码大致如下:
ServerSocket ss = new ServerSocket(1900);
Socket s = ss.accept();
InputStream is = s.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is,Charset.forName(”UTF-8″)));
String line = “”;
while ((line = in.readLine()) != null) {
System.out.println(line.toString());
}
is.close();
in.close();
s.close();
ss.close();