Socket Problem: Server for Web-Browser-Client

D

dietmar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top