Socket Problem: Server for Web-Browser-Client

Discussion in 'Java' started by dietmar, Oct 7, 2005.

  1. dietmar

    dietmar Guest

    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.



    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();

    IE-call: http:\\localhost
    dietmar, Oct 7, 2005
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.