File over socket problems

I am trying to send a zip file from a client to a server using sockets. I can get the file to transfer all right but the server "halts" after the send. Using trace debugging I can see that the while loop is exiting but any statement afterwards is not being processed. I have tried several different "stream" methods and I still can't figure it out.

Client Code

output =new DataOutputStream(client.getOutputStream());

byte[] buffer =newbyte[1024];

int r;

InputStream in =new FileInputStream(path +"\\" + file+ ".zip");

while((r = in.read(buffer)) > 0)

{

output.write(buffer,0,r);

}

output.flush();

input.close();

output.close();

Server Code

input =new DataInputStream(connection.getInputStream());

OutputStream out =new FileOutputStream(outFile);

byte[] buffer =newbyte[1024];

int r;

while((r = input.read(buffer)) > 0)

{

out.write(buffer,0,r);

}

out.flush();

out.close();

input.close();

//This doesn't display, any idea?

System.out.println("Completed");

Message was edited by:

jwarzech

[1851 byte] By [jwarzecha] at [2007-11-27 2:23:14]
# 1
Your code looks good to me. Are you getting past output.close() in the client? and is this a straight Socket connection or an HttpURLConnection to a servlet?
ejpa at 2007-7-12 2:28:26 > top of Java-index,Core,Core APIs...
# 2
input.close() to be in.close() on the client
developer_jbsa at 2007-7-12 2:28:26 > top of Java-index,Core,Core APIs...
# 3

I fixed my problem it was that I wasn't closing the streams after file transfer. I originally didn't do this because I was using one set of streams for communication in my program. I just used a new set of streams for file transfer and closed them when file transfer was completed.

Message was edited by:

jwarzech

jwarzecha at 2007-7-12 2:28:26 > top of Java-index,Core,Core APIs...