Hi,
I'm using Inputstream to read an HTTP request from my browser (i'm
actually making a proxy).
The code:
InputStream in = new DataInputStream(socket.getInputStream());
ArrayList<Integer> byteArray = new ArrayList<Integer>();
int currByte=in.read();
while (currByte!=-1){ // Reading byte until -1 is reached
byteArray.add(new Integer(currByte));
System.out.print((char)currByte);
currByte = in.read();
}
For some reason, instead of recognizing the end of the request and
returning -1 InputStream.read() blocks forever.
Am i doing something wrong??
Thanks,
Ben.
Finomosec - 16 Feb 2006 23:19 GMT
Ben schrieb:
> Hi,
>
[quoted text clipped - 15 lines]
> Thanks,
> Ben.
See Thread: "writing a proxy ..."
news.online.de comp.lang.java.programmer:631136
There is more advanced code for a proxy.
There may be a EOT or EOF signal, that indicates the end of the stream.
But anyway you should implement a timeout in case the browser aborts the
request, or the connection is lost before end of the request/answer.
Maybe its better to take an existing Java-Proxy and modify it to your needs.
Maybe this can be used (found it on a quick google search):
http://simile.mit.edu/httptracer/index.html
This looks like the main proxy-class:
http://simile.mit.edu/repository/httptracer/trunk/src/edu/mit/simile/tools/httpt
racer/Connection.java
Greetings Finomosec;