|
-
Send a file from client to server
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks