发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 大数据 扩展性 并发编程 事件驱动 分布式 SOA

java Socket接收数据乱码问题

2006-08-02 13:14
赞助商链接

系统发送数据代码:
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
2006-08-08 09:53

还是那句老话,统一编码即可

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com