各位,小弟目前正开发一个项目,涉及到java后台和前置机(C开发的)间的通讯。
当数据量不大时(6000B左右)时正常,但当数据超过13000B时,每次java后台接收前置机返回的数据时都抛出connection reset异常(debug时发现为 in.readLine()时异常)。不知真正原因在哪里(下面为java后台相关代码),急盼高人的解答。急,在线等……
……
//建立网络连接
Socket client;
try
{
client = new Socket(ip, Integer.parseInt(port)); int soTimeOut = Integer.parseInt(timeOut); if (soTimeOut > 0)
{
//设置超时毫秒数
client.setSoTimeout(soTimeOut);
} BufferedReader in = new BufferedReader(new InputStreamReader(client
.getInputStream())); PrintWriter out = new PrintWriter(client.getOutputStream());
//增加报头信息 客户现场
String branch = DataTools.getBranchByIP(ip);
String size = String.valueOf(xmlString.getBytes().length);
String titleXml = com.neusoft.finance.common.DataTools.leftMendStringLen(size,8,' ');
String branchXml= com.neusoft.finance.common.DataTools.leftMendStringLen(branch,8,' ');
xmlString = titleXml.concat(branchXml).concat(xmlString);
log.info("发送的xml:"+xmlString);
out.println(xmlString); out.flush(); //前置机返回数据
returnString = in.readLine();
log.info("返回的xml:"+returnString);
client.close();
}
catch (NumberFormatException e)
{
ExcAct.doHandle(e);
throw new SystemException(e);
}
catch (UnknownHostException e)
{
ExcAct.doHandle(e);
throw new SystemException(e);
}
catch (IOException e)
{
ExcAct.doHandle(e);
throw new SystemException(TradeConstCodeList.CONNECT_TIME_OUT,e,ip);
}
catch (Exception e){
ExcAct.doHandle(e);
throw new SystemException(e);
}
……
当数据量不大时(6000B左右)时正常,但当数据超过13000B时,每次java后台接收前置机返回的数据时都抛出connection reset异常(debug时发现为 in.readLine()时异常)。不知真正原因在哪里(下面为java后台相关代码),急盼高人的解答。急,在线等……
……
//建立网络连接
Socket client;
try
{
client = new Socket(ip, Integer.parseInt(port)); int soTimeOut = Integer.parseInt(timeOut); if (soTimeOut > 0)
{
//设置超时毫秒数
client.setSoTimeout(soTimeOut);
} BufferedReader in = new BufferedReader(new InputStreamReader(client
.getInputStream())); PrintWriter out = new PrintWriter(client.getOutputStream());
//增加报头信息 客户现场
String branch = DataTools.getBranchByIP(ip);
String size = String.valueOf(xmlString.getBytes().length);
String titleXml = com.neusoft.finance.common.DataTools.leftMendStringLen(size,8,' ');
String branchXml= com.neusoft.finance.common.DataTools.leftMendStringLen(branch,8,' ');
xmlString = titleXml.concat(branchXml).concat(xmlString);
log.info("发送的xml:"+xmlString);
out.println(xmlString); out.flush(); //前置机返回数据
returnString = in.readLine();
log.info("返回的xml:"+returnString);
client.close();
}
catch (NumberFormatException e)
{
ExcAct.doHandle(e);
throw new SystemException(e);
}
catch (UnknownHostException e)
{
ExcAct.doHandle(e);
throw new SystemException(e);
}
catch (IOException e)
{
ExcAct.doHandle(e);
throw new SystemException(TradeConstCodeList.CONNECT_TIME_OUT,e,ip);
}
catch (Exception e){
ExcAct.doHandle(e);
throw new SystemException(e);
}
……
莫非你也是?呵呵
“BufferedReader(Reader in, int sz) 使用这个构造一次”,你是指对BufferedReader in = new BufferedReader(new InputStreamReader(client
.getInputStream()))?
看下这个吧
结贴去了。