I'm having a problem getting my entire file transferred across the socket connection. The first buffer comes across fine.
What's happening is that I do get the first set of bytes, but from then on, I keep getting the same bytes (on the client side) every time.
I think maybe the writeObject() I'm using to write a new array of bytes isn't working as I expected.
I print out on the server side what I've read and it's correctly advancing though the file. However, either the writeObject() call or something is incorrect. Basically, I'm trying to write the buffer I read on the server side to the client who reads it.
The server code does stuff like this:
======================================
{
// read a chunk into the buffer, then write them out.
// keep looping until we reach the end of the file
// (when read() returns -1).
bytes_read = from.read(buffer);
output.writeObject(buffer);
output.flush();
for (int x = 0; x < buffer.length; x++)
{
outText.append((char) buffer[x]);
}
System.out.println("This read:\n" + outText);
outText.setLength(0);
// wait until client is ready for more.
do
{
// nothing...loop...
}
while (!input.readObject().equals("CLIENT>>> Read OK."));
} while (bytes_read != -1);
==============================================
The client code looks like this:
===============================================
do
{
try
{
buffer = (byte[]) input.readObject();
output.writeObject("CLIENT>>> Read OK.");
output.flush();
for (int x = 0; x<buffer.length; x++)
{
outText.append((char) buffer[x]);
}
this.jTextArea_ServerResponse.append("\n" + "Client>>>" +outText);
// write buffer to file...
out.write(buffer);
// reset
string buffer
outText.setLength(0);
}
=======================================
Can anyone tell me why this doesn't work and what I need to do to fix it?
THANKS MUCH IN ADVANCE!!!
--Mike