当前位置: 代码迷 >> GIS >> 接收GPS终端数据乱码解决方法
  详细解决方案

接收GPS终端数据乱码解决方法

热度:98   发布时间:2016-05-05 06:25:14.0
接收GPS终端数据乱码
hhhH?++/ '#
hhhH馃
hhhH?

代码
public void doService(){
System.out.println("server doService now!");
while(server!=null){
Socket socket=null;
InputStream in=null;
OutputStream out=null;
try {
socket = server.accept();
in=getBufferedInputStream(socket);
byte[] tmp=new byte[1024];
int re=-1;
while((re=in.read(tmp))!=-1){
System.out.println(new String(tmp,0,re));
}
out=getBufferedOutputStream(socket);
out = getBufferedOutputStream(socket);
out.write("i have received your message!".getBytes());
out.write(new byte[] { 0x0d, 0x0a });
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try{
in.close();
out.close();
socket.close();
}catch (Exception e) {
// TODO: handle exception
}

}

}
}

------解决方案--------------------
你没转16进制字符串当然乱了
  相关解决方案