关于socket读取字节流的问题

下面是我写的源码,每次在读取数据的时候在“开始循环”下面的for循环里面就出问题了;请问各位大侠我的代码有什么问题?
try {
// 1接收消息
serverInput = s.getInputStream();
//serverOutput = s.getOutputStream();
System.out.println("新系统收到的消息 --------start ------------------------------------ ");

int imLen = 2 + 2 + 2 + 8 + 2;
byte[] lenBuffer=new byte[imLen];
for(int i=0;i<imLen;i++)
{
lenBuffer[i]=(byte)serverInput.read();
}
String sss = new String(lenBuffer,"gb2312");

serverOutput.write(lenBuffer);

System.out.println(" 收到的消息 sss == " + sss);
int xmlLen = 4;
byte[] xmlBuffer=new byte[xmlLen];
for(int i=0;i<xmlLen;i++)
{
xmlBuffer[i]=(byte)serverInput.read();
}
String sss2 = new String(xmlBuffer,"iso8859-1");
int xmlFileLen = IntTools.byteToInt(xmlBuffer);
System.out.println(" 收到的消息 sss2 == " + xmlBuffer.length);
byte[] line= new byte[xmlFileLen];
System.out.println(" 开始循环 " );
for(int i=0;i<xmlFileLen;i++)
{
line[i]=(byte)serverInput.read();
}
System.out.println(" 结束循环 " );
String xmlFile = new String(line,"gb2312");

System.out.println(" 收到的xml文件内容 == " + xmlFile);

int iLen = 2;
byte[] ib=new byte[iLen];
System.out.println(" xml ");
for(int i=0;i<iLen;i++)
{
ib[i]=(byte)serverInput.read();
}
System.out.println(" xml ");
String sss3 = new String(ib,"gb2312");
System.out.println("ProcessSocket 收到的消息 sss3 == " + sss3);

System.out.println("新系统收到的消息 --------end ------------------------------------------------------------------ ");
这个还奇怪的很 我捕获异常了 但是没有异常的日志!

第1个回答  2010-08-17
没有数据传过来,读取数据时阻塞了,没有异常
第2个回答  2010-08-16
把异常打印出来贴出来看看啊,这咋看

lenBuffer[i]=(byte)serverInput.read();

如果是这句出问题有可能是空指针错误本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网