错误! java.io.EOFException的

时间:2013-09-23 15:39:24

标签: java android network-programming eof

我收到错误信息已达到EOF文件,我正在做的只是读取和写入长值,这是通过套接字的文件的大小,但我在客户端Java.io.EOFexception得到错误代码是这样的 客户端(Android的)

try 
            {

                Log.v("read size and number", "item");
                soc = new Socket(InetAddress.getByName(ip), 3838);
                output = new ObjectOutputStream(soc.getOutputStream());
                output.writeUTF(Constants.REQUEST_SIZE_AND_NUMBER+","+path);
                output.flush();
                input = new ObjectInputStream(soc.getInputStream());
        System.out.println("size......");
                    size =  input.readLong();

            } 
            catch (UnknownHostException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
            catch (IOException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         finally
         {
             closeConnection();
         }

服务器

 try
{
  System.out.println("Request size.....");
                   long size = diskinfo.folderSize(new File(path));
                   System.out.println("Size of folder "+size);
                   out = new ObjectOutputStream(soc.getOutputStream());
                      out.writeLong(size);
                      out.flush();
}
 catch (IOException ex)
            {
                Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
            }
finally
{
  closeConnection() //closing input, output and socket
}

生成日志

09-23 20:56:45.573: W/System.err(5042): java.io.EOFException
09-23 20:56:45.573: W/System.err(5042):     at java.io.DataInputStream.readShort(DataInputStream.java:375)
09-23 20:56:45.573: W/System.err(5042):     at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2388)
09-23 20:56:45.573: W/System.err(5042):     at java.io.ObjectInputStream.<init>(ObjectInputStream.java:445)
09-23 20:56:45.573: W/System.err(5042):     at com.example.diskexplorer.Client$SizeAndNumberTask.doInBackground(Client.java:138)
09-23 20:56:45.573: W/System.err(5042):     at com.example.diskexplorer.Client$SizeAndNumberTask.doInBackground(Client.java:1)
09-23 20:56:45.573: W/System.err(5042):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-23 20:56:45.573: W/System.err(5042):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-23 20:56:45.573: W/System.err(5042):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-23 20:56:45.573: W/System.err(5042):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
09-23 20:56:45.573: W/System.err(5042):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
09-23 20:56:45.573: W/System.err(5042):     at java.lang.Thread.run(Thread.java:1096)

0 个答案:

没有答案