While(true){
//listen to the client
//handle request
//open socket to send request to the relative browser
byte[] buf3 = new byte[4*1024]
/receive stream from browser
while ((c = infromhttpserver.read(buf3)) !=
{
outtoBrowser.write(buf3,0,c);
writetofile.write(buf3,0,c);
System.out.println(c);
}
Two thing that I didn't know:
i. I force the buf3 to be 4Kbytes, but the I found from System.out.println(c) that the byte readed always vary.
ii. When requested a html, it written that loop to get the link of other file, such as /image/abc.jpg. However, when it go to the while loop of infromhttpserver.read(buf3). It will loop few times that get not so many Kbytes of data and then error occur like the followings:
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(Unknown Source)
at localproxy.run(localproxy.java:176)
I made the conclusion that connection closed by the server even if the stream of the picture not completely received.
Let say a pic of 10MB, it always read, let say, about few hundred Kbytes and then the connection close. How to solve it?
If the problem is just a simple as "connection not stable", why did there is no problem if I request the server directly without my proxy program. I mean the browser always can browser through the pages with the picture completely load.
Hope to receive your reply. Thanks a lot for the support!
Joe
-Eric