java Socket接收数据乱码问题

06-08-02 毛毛虫
系统发送数据代码:

socket = new Socket(SysConfigInfo.getConfigInfo().getMsgIp(),

SysConfigInfo.getConfigInfo().getMsgPort());

outStream = new DataOutputStream(socket.getOutputStream());

//优先级

outStream.writeInt(nOrder);

//动作

outStream.writeInt(nAction);

//类型

outStream.writeInt(nMode);

outStream.flush();

outStream.close();

outStream = null;

socket.close();

接收socket的数据用C写的,现在需要用java写,如下:

public ServerThread(Socket s)

{

//接收receiveServer传来的套接字

this.m_ClientRequest = s;

InputStreamReader reader;

OutputStreamWriter writer;

try

{

//初始化输入、输出流

reader = new InputStreamReader(m_ClientRequest.getInputStream());

writer = new OutputStreamWriter(m_ClientRequest.getOutputStream());

//out = new PrintWriter(m_ClientRequest.getOutputStream(),true);

m_Input = new BufferedReader(reader);

m_Output = new PrintWriter(writer,true);

}

catch(IOException e)

{

System.out.println(e.getMessage());

}

}

public void run()

{

String strSql = null;

char [] buffer = new char[8192];

String sReturn = null;

int nDataLen;

Msg = new ShowMsg("数据处理线程启动:" + getName());

try

{

//读取客户端发送的数据

nDataLen = m_Input.read(buffer);

if(nDataLen > 0 )

{

//strSql = String.valueOf(buffer,0,nDataLen - 1 );

strSql = buffer.toString();

byte[] tmp = strSql.getBytes();

//System.out.println("" +tmp);

for(int i = 0; i < tmp.length; i ++){

//out.print(tmp);

System.out.println("" + String.valueOf(tmp));

}

1
banq
2006-08-08 09:53
还是那句老话,统一编码即可

猜你喜欢