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
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
while (true)
{
// read a buffer from is
// if no more data, escape from while loop
// process the data contained in the buffer
}
Data response
protected void doGet(HttpServletRequest req, HttpServletResponse
res) throws ServletException, IOException {
OutputStream os = res.getOutputStream();
while (true)
{
// read a buffer from a large file
// modify buffer according to application logics
// if no more data, escape from while loop
// write modified buffer to os
}
}
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