944,022 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2551
  • Java RSS
Mar 9th, 2005
0

Question about URLConnection

Expand Post »
Hello everyone,


I am using HTTP protocol to transfer large amount of data across two machines. And I have found out that some packages will be lost when using the following source codes. I am wondering whether there are anything wrong or potential issues in them.

Data request

Java Syntax (Toggle Plain Text)
  1. URLConnection conn = url.openConnection();
  2. conn.connect();
  3. InputStream is = conn.getInputStream();
  4. while (true)
  5. {
  6. // read a buffer from is
  7.  
  8. // if no more data, escape from while loop
  9.  
  10. // process the data contained in the buffer
  11. }

Data response

Java Syntax (Toggle Plain Text)
  1. protected void doGet(HttpServletRequest req, HttpServletResponse
  2.  
  3. res) throws ServletException, IOException {
  4.  
  5. OutputStream os = res.getOutputStream();
  6. while (true)
  7. {
  8. // read a buffer from a large file
  9.  
  10. // modify buffer according to application logics
  11.  
  12. // if no more data, escape from while loop
  13.  
  14. // write modified buffer to os
  15. }
  16.  
  17. }

I am wondering whether the package losing is caused by the reason that, data response is too fast than data receiving so data receiving application will miss some chances to read packages.

I am also wondering what is the effective approach of transfering data across two machines using HTTP protocol without losing any packages. Are there any online samples?


Thanks in advance,
George
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004
Mar 9th, 2005
0

Re: Question about URLConnection

I could be wrong about this, but I would think no matter how you do it, it would be possible to loose some packets due to the quality of the connection, and so forth. Again, I could be wrong, so maybe somone that knows a little more than me can help you.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 9th, 2005
0

Re: Question about URLConnection

Thanks server_crash,


Quote originally posted by server_crash ...
I could be wrong about this, but I would think no matter how you do it, it would be possible to loose some packets due to the quality of the connection, and so forth. Again, I could be wrong, so maybe somone that knows a little more than me can help you.
Your idea is very helpful. Do you know any online resources dealing with similar topics?


regards,
George
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004
Mar 10th, 2005
0

Re: Question about URLConnection

Sorry, I don't know very much about network programming. Hopefully, someone that knows something about it will come along and help you. sorry!
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 10th, 2005
0

Re: Question about URLConnection

Never mind server_crash, thanks all the same.


Quote originally posted by server_crash ...
Sorry, I don't know very much about network programming. Hopefully, someone that knows something about it will come along and help you. sorry!

regards,
George
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: number formatting using recursion
Next Thread in Java Forum Timeline: cannot link a form to a nonform application in microsoft j++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC