Client:
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream( ));
FileInputStream infile=new FileInputStream(file);
byte b[]=new byte[(int)file.length()];
infile.read(b);
String str=new String(b);
out.write(str);
System.out.println(str);
out.write("\r\n");
out.flush();

Server:

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream( )));
StringBuffer response = new StringBuffer( );
String theLine = null;
while ((theLine = in.readLine( )) != null) {
response.append(theLine);
response.append("\r\n");
}

1. "connection" is a Socket.
2. "file" is an ASCII File, which will be sent to server


The problem I met is: after the server received the whole file content, it can't return "null", but still waited for the next line. So the server stuck and wait for ever.


How can I solve this problem?
Thanks a lot!