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.

    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
     
    dietmar, Oct 7, 2005
    #1
    1. Advertising

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.
Similar Threads
  1. Avizz
    Replies:
    3
    Views:
    13,819
    Andy Fish
    Sep 29, 2003
  2. greatestmclarenfan
    Replies:
    2
    Views:
    581
    Steve Horsley
    Feb 16, 2006
  3. Laszlo Nagy
    Replies:
    1
    Views:
    4,852
    Mark Wooding
    Jan 27, 2009
  4. Jean-Paul Calderone
    Replies:
    0
    Views:
    970
    Jean-Paul Calderone
    Jan 27, 2009
  5. Laszlo Nagy
    Replies:
    0
    Views:
    550
    Laszlo Nagy
    Feb 1, 2009
Loading...

Share This Page