Why EOFException occurs?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Why EOFException occurs?

  1. #1
    Join Date
    Nov 2007
    Posts
    9

    Why EOFException occurs?

    Hello,

    I am trying to send byte array from C++ to Java app, but EOFException always occurs. Why is that?

    I send through this C++ code (thanks to hendrixj):
    Code:
    ...
        // Change-back endian to network order.
        ni = ::htonl(hi); // "hi" index of hdata[hi][hj]
        nj = ::htonl(hj); // "hj" index of hdata[hi][hj]
        
        for(int i = 0; i < hi; i++) {
            for(int j = 0; j < hj; j++) {
                ndata[i][j] = ::htonl(hdata[i][j]); // every content of hdata[hi][hj]
            }
        }
        
        // Sending-back the indexes and the array.
        if(send(connectSocket, ∋, sizeof(int), 0) < 0) { // send-back "ni" index
            cerr << "Couldn't send-back first index.";
            exit(1);
        }
        
        if(send(connectSocket, &nj, sizeof(int), 0) < 0) { // send-back "nj" index
            cerr << "Couldn't send-back second index.";
            exit(1);
        }
        
        if(send(connectSocket, &ndata, sizeof(int) * hi * hj, 0) < 0) { // send-back ndata[hi][hj] array
            cerr << "Couldn't send-back " << hi << " x " << hj << " data.";
            exit(1);
        }
    ...
    And I receive using this Java code:
    Code:
                // Receive the byte array.
                bytesNum = is.read(b);
                inBytes = new byte[bytesNum];
                System.arraycopy(b, 0, inBytes, 0, bytesNum);
            
                // Read the byte stream into integer array.
                bais = new ByteArrayInputStream(inBytes);
                dis = new DataInputStream(bais);
                
                ii = dis.readInt();
                jj = dis.readInt();
                
                System.out.println("i = " + ii + " j = " + jj);
                newTwoD = new int[ii][jj];
                
                System.out.print("Received: |");
                for (int i = 0; i < ii; i++) {
                    for (int j = 0; j < jj; j++) {
                        newTwoD[i][j] = dis.readInt();
                        if (newTwoD[i][j] != arrTwoD[i][j]) {
                            System.err.println("newTwoD[" + i + "][" + j + "] = " + newTwoD[i][j] + " != arrTwoD[" + i + "][" + j + "] = " + arrTwoD[i][j]);
                        } else {
                            System.out.print(newTwoD[i][j] + "|");
                        }
                    }
                }
                System.out.println();
    Is there anybody can tell me why I get this message?
    java.io.EOFException
    at java.io.DataInputStream.readInt(DataInputStream.java:375)
    at EchoJava.main(EchoJava.java:83)
    Please help me and Thank you very much.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    What is the statement at line 375?

    It looks to me that the program is executing a "nextInt" method and finds nothing there (it has gone beyond the end of the file). Has it read anything of the file when the exception is thrown? Is your loop detecting the end of the input stream?

Similar Threads

  1. Replies: 1
    Last Post: 07-23-2006, 01:21 PM
  2. Replies: 0
    Last Post: 03-02-2006, 11:39 AM
  3. urgent: session timeout occurs unexpectedly
    By seemagaur in forum ASP.NET
    Replies: 1
    Last Post: 01-26-2006, 09:24 AM
  4. Re: Error 458 occurs randomly... SOLVED!!!
    By Bernie in forum VB Classic
    Replies: 3
    Last Post: 04-01-2003, 08:23 AM
  5. Replies: 0
    Last Post: 04-12-2001, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center