我server起来以后
1 客户端先发请求,server收到后给出应答,这时是没有问题的
2 现在如果客户端发完消息,server不给应答,则抛出异常!
代码如下
      in = new DataInputStream(socket.getInputStream());
      dataLen = in.readInt();
      抛出异常是java.io.EOFException我已经设置client的超时时间了60*1000,现在想达到的效果是如果server没有响应,则到超时时间后才抛异常的!我哪里设置的不正确吗?

解决方案 »

  1.   

    byte[] requestData = null;
          byte[] responseData = null;
          try {
            DataInputStream in = null;
            DataOutputStream out = null;        try {
              out = new DataOutputStream(socket.getOutputStream());
              out.writeInt(req.length);
              out.write(req);
              out.flush();
            }  //如果发送out包,server没有给应答,则抛出异常
            catch (IOException ex) {
              throw new NetException(NetException.WRITE_DATA_ERROR, "写数据错误", ex);
            }
            int dataLen = 0;
            //如果不发送out包,则能正常抛出超时异常!
            try {
              in = new DataInputStream(socket.getInputStream());
              dataLen = in.readInt();
            }
            catch (IOException ex) {
              throw new NetException(NetException.READ_DATA_ERROR, "读数据错误", ex);
            }
    我现在想达到的效果是,不发送out包,也能正常抛出异常!
      

  2.   

    说的有点乱:s,
    我想达到的效果是,如果发送out包,但server没有给出应答,则也能到超时时间后再抛出异常.