views:

417

answers:

2

Hi all,

I have a server that basically caters to multiple clients. I am basically using gzip(input/output)stream to compress the data between client-server.

Many clients can send the requests to server at the same time and hence i have a thread to cater to each client.

Now, the problem tat i am experiencing is that "randomly" some client code fails whenever it tries to execute following after the connection to the server has been established.

`GZIPInputStream in = new GZIPInputStream(server.getInputStream());`

I get java.io.EOFException.

And when i say randomly, i mean there is no pattern that i can find in the exception. The requests are being send properly (else it would not work for any client requests).

I have searched a lot..but couldnt find anything.. :(

Any pointers on the above problem ??

Thanks,

+1  A: 

What is the error rate? Could it be that these are random (occasional) network errors? Or perhaps your server is occasionally experiencing an internal error?

It doesn't really sound like the problem is with the GZip data itself, but rather with an occasional network break. My guess is that your server occasionally generates an exception and sends an invalid stream, causing this type of error on the client. Perhaps try logging all exceptions on the server to insure that you aren't occasionally getting internal failure there?

jsight
hi,i doubt if the network is an issue becauuse for now , client-server app run on the same machine( for testing purposes).If i try reading from a BufferedInputStream, then i find none of these errors..The main reason i chose to compress the data is because i have around 130KBs of data that has to be exchanged between the client-server, and using BufferedInputStream, i wwas able to read only partially.. :( !!insights on the above ?
If the type of stream matters, then there must be some odd bug in the code. Is there any way to post the code that causes the issue?
jsight
Heres the stacktrace of the exception i get..java.io.EOFException at java.util.zip.GZIPInputStream.readUByte(Unknown Source) at java.util.zip.GZIPInputStream.readUShort(Unknown Source) at java.util.zip.GZIPInputStream.readHeader(Unknown Source) at java.util.zip.GZIPInputStream.<init>(Unknown Source) at java.util.zip.GZIPInputStream.<init>(Unknown Source) at com.WebServerVNCRequest.doGet(WebServerVNCRequest.java:78)
A: 

Hi heres the code snippet from my application... Client code that connects to the server, makes a request and waits for a response... There could be many simultaneous such requests meant for the server....

Socket connection= new Socket("localhost",2428);
GZIPOutputStream out = new GZIPOutputStream(connection.getOutputStream());
out.write(url.getBytes());
out.finish();
GZIPInputStream in=null;

 try
     {
     in = new GZIPInputStream(connection.getInputStream(),1024); // Exception raised here
     }
     catch(Exception e){
       }

Server code that accepts a new connection and spawns a new thread.

ServerSocket dsWeb= new ServerSocket(2428);
Socket webClient;
while(true){
webClient = dsWeb.accept();

executor.execute(new ThreadPool()); // each request to be handled by a separate thread 

}

The code within the thread ..

GZIPInputStream inWeb = new GZIPInputStream(webClient.getInputStream());
int c1=0;
byte[] b1 = new byte[100000];
c1=inWeb.read(b1);
//Process the request
GZIPOutputStream outWeb = new GZIPOutputStream(webClient.getOutputStream());
outWeb.write(/* Response */);
outWeb.finish();

Do you find anything amiss in the code ???

Thanks,

the "1024" in the client code is not actually present... i had just added it while debugging..
Why is your byte array so large? Is there any way to read the the stream in smaller chunks? It's totally a guess here but I'm wondering if you're getting some sort of overflow error somewhere?
MattC
i have kept the byte array to be large because the size of the data that is actually being sent is around 130KB so to be on a safer side... i hv used 100KB buffer space....nop..i am not getting any overflow errors.. :-/ ... we can discount tat as a posible coz..