D
Dave Rudolf
Hi all.
I was just playing around with output streams, and I noticed something
interesting. Suppose that I have a socket between two processes. On each end
of the socket, I put an ObjectInputStream and an ObjectOutputStream. I then
serialize objects over the socket via the object streams and everything
works just fine. But, if I put a GZIPOutputStream between the
ObjectOutputStream and the sockets out stream (and similar for the input
streams) then the app hangs on me when I create the ObjectInputStream.
Perhaps some code will illustrate what I'm talking about.
// Client code
Socket sock = new Socket( "www.disco.com", 1234 );
ObjectOutputStream outStream = new ObjectOutputStream(
new GZIPOutputStream( sock.getOutputStream() );
ObjectInputStream inStream = new ObjectInputStream(
new GZIPInputStream( sock.getInputStream() );
// Server code
ServerSocket svrSock = new ServerSocket( 1234 );
Socket sock = svrSock.accept();
ObjectOutputStream outStream = new ObjectOutputStream(
new GZIPOutputStream( sock.getOutputStream() );
ObjectInputStream inStream = new ObjectInputStream(
new GZIPInputStream( sock.getInputStream() );
Both apps hang when they try to create the ObjectInputStream. The reason
seems to be that the ObjevtInputStream waits for the other end to send
certain initialization data along, but the GZIP stream is holding back the
raw bytes -- it wants more data before it can deflate and transmit a block.
Is this correct?
Even if I put an outStream.flush() before creating the input stream, it
still hangs. If I call finish() on the GZIPOutputStream, then I gen an
exception the next time I do a write. Any suggestions on how to force the
data across without finishing the stream?
Dave.
I was just playing around with output streams, and I noticed something
interesting. Suppose that I have a socket between two processes. On each end
of the socket, I put an ObjectInputStream and an ObjectOutputStream. I then
serialize objects over the socket via the object streams and everything
works just fine. But, if I put a GZIPOutputStream between the
ObjectOutputStream and the sockets out stream (and similar for the input
streams) then the app hangs on me when I create the ObjectInputStream.
Perhaps some code will illustrate what I'm talking about.
// Client code
Socket sock = new Socket( "www.disco.com", 1234 );
ObjectOutputStream outStream = new ObjectOutputStream(
new GZIPOutputStream( sock.getOutputStream() );
ObjectInputStream inStream = new ObjectInputStream(
new GZIPInputStream( sock.getInputStream() );
// Server code
ServerSocket svrSock = new ServerSocket( 1234 );
Socket sock = svrSock.accept();
ObjectOutputStream outStream = new ObjectOutputStream(
new GZIPOutputStream( sock.getOutputStream() );
ObjectInputStream inStream = new ObjectInputStream(
new GZIPInputStream( sock.getInputStream() );
Both apps hang when they try to create the ObjectInputStream. The reason
seems to be that the ObjevtInputStream waits for the other end to send
certain initialization data along, but the GZIP stream is holding back the
raw bytes -- it wants more data before it can deflate and transmit a block.
Is this correct?
Even if I put an outStream.flush() before creating the input stream, it
still hangs. If I call finish() on the GZIPOutputStream, then I gen an
exception the next time I do a write. Any suggestions on how to force the
data across without finishing the stream?
Dave.