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):
And I receive using this Java code: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); } ...
Is there anybody can tell me why I get this message?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();![]()
Please help me and Thank you very much.java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at EchoJava.main(EchoJava.java:83)


Reply With Quote


Bookmarks