my server programm sends a response (e.g. HTML-code) to the requested
web-browser-client (firefox or IE).
It works, but only when the request data in the input-stream from the
client-socket are read.
Why??
Dietmar
see the example code:
...
ServerSocket server = new ServerSocket(80); // any other port(9991);
Socket client=server.accept();
String ip=client.getInetAddress().toString();
// Read request from client-socket input-stream
// if the entire read code is marked out as commentar,
// it doesn't worked.
InputStream is = client.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StringBuffer request= new StringBuffer();
while ((r=br.readLine()).length()!=0)
{
request.append(r + "\n");
}
// Write response to client
OutputStream os = client.getOutputStream();
Date date=new Date();
String s= "<html> <head><title>Hallo Web</title></head>"+
"<body><h1>HELLO" + ip + " im WEB</h1>"+"</body>";
byte b[]=s.getBytes();
os.write(b);
...
IE-call: http:\\localhost
Roedy Green - 08 Oct 2005 00:10 GMT
> while ((r=br.readLine()).length()!=0)
> {
> request.append(r + "\n");
> }
just a stylistic aside, I would write that as :
while ((r=br.readLine()).length()!=0)
{
request.append(r);
request.append( '\n');
}
To avoid creating an extra StringBuffer every time round the loop.
The other thing is you carefully find the \ns and then hide them
again. I would have expected code more like this that preserves the
lines:
while ((r=br.readLine()).length()!=0)
{
lineArrayList.add( r );
}

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Roedy Green - 08 Oct 2005 00:15 GMT
> String s= "<html> <head><title>Hallo Web</title></head>"+
> "<body><h1>HELLO" + ip + " im WEB</h1>"+"</body>";
> byte b[]=s.getBytes();
Again some peripheral issues likely not related to your problem.
Your <html> tag is unbalanced.
getBytes is using the SERVER'S platform default encoding. It a real
app you want to use client's preferred encoding.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Roedy Green - 08 Oct 2005 00:17 GMT
>It works, but only when the request data in the input-stream from the
>client-socket are read.
And when you don't read the entire input stream what happens?
1. an exception? what was it? What was the stack trace?
2. there is no response at all with no message?
3. you get some sort of garbled response? What was it. See
http://mindprod.com/jgloss/packetsniffer.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.