Fw: Newbie - Please help !!!

Hi Again,

The following is the code snippets from my Java server, which may be useful in understanding my Libwww usage:

Java server (Jetty):
            ServerSocket m_socket = new ServerSocket (1400, 5);
            Socket incoming = m_socket.accept();
            HttpConnection httpCon = new HttpConnection (incoming.getInputStream(), incoming.getOutputStream());

            for (int i=0;;i++)
            {
                incoming.setSoTimeout(0);
                // Waiting for request from client
                httpCon.handle();
                HttpRequest m_request = httpCon.getRequest();
                DataInputStream in = new DataInputStream (m_request.getInputStream());
                byte arr[] = new byte[1024];
                int len = in.read(arr);
                System.out.println("Received -> " + new String (arr, 0, len));
    
                // Sending the response to client
                String resp = new String ("i can hear you " + i);
                HttpResponse response = httpCon.getResponse();
                response.setIntField(HttpFields.__ContentLength, (int) resp.getBytes().length);
                response.setField(HttpFields.__Connection,HttpFields.__KeepAlive);
                response.setField(HttpFields.__AcceptRanges,"bytes");
                Writer writer = response.getOutputStream().getRawWriter();
                 response.writeHeader(writer);
                DataOutputStream out = new DataOutputStream (response.getOutputStream());
                out.write(resp.getBytes());
                System.out.println("Sending the data to client..");
                httpCon.getOutputStream().flush();
                httpCon.getOutputStream().resetStream();
                httpCon.getInputStream().resetStream();
            }

The server simply waits for requests from the client and then sends back the response. How do I accomplish this using Libwww. Is the following approach correct:

  status = HTPostAnchor(src, anchor, request);
  if (status == YES)
       HTEventList_loop(request);

  printf ("Receiving data from server..\n");
  status = HTLoadAnchor(anchor, request);
  if (status == YES)
       HTEventList_loop(request);

The first event loop call hangs and some exception gets thrown on the server-side. I am sure that above code has some problem since my Java Http client does not cause any problem. What should be the correct usage? What sort of connection mode should be set? Anything related to terminate handler? Please help.. Urgent!!

Thanks
Nitin


----- Original Message ----- 
From: Nitin Duggal 
To: www-lib@w3.org 
Sent: Wednesday, May 29, 2002 3:09 PM
Subject: Newbie - Please help !!!


Hi All,
 
I am trying to use Libwww for communicating with HTTP Java server implemented using Jetty (java open-source). I am unable to understand the purpose of Event Loop and when does the function call HTEventList_loop terminates. 
 
I am posting some text message to the http server and then entering the Event loop, but my application gets stuck. I have also set the required after filter to stop the loop. But it is not getting invoked. However it is working perfectly for GET function calls. What could be the reason for this. 

Please help. Any docs for understanding the APIs or will I have to explore the entire code.

Thanks
Nitin

Received on Wednesday, 29 May 2002 07:09:03 UTC