Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

some socket question

1 view
Skip to first unread message

Joe Wong

unread,
Sep 26, 2001, 5:37:52 AM9/26/01
to
Dear All,
I wanna ask how did the response from the server response to the browser.
I am writing a proxy server. It can received the broswer stream.

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 Anderson

unread,
Sep 29, 2001, 12:13:44 AM9/29/01
to
If I understand what you're doing correctly, and if you're getting a socket
*write* error, then it would seem that the exception is originating from
your write() to the browser client, and not from the socket connection to
the server. The browser might be dropping your connection for any number
of reasons - you might be mangling the HTTP protocol, sending incorrectly
encoded data, or it might just think that it's received all that the server
plans to send it.

-Eric

0 new messages