On Wed, 28 Nov 2001 16:05:32 -0700, Gardner Monte <[EMAIL PROTECTED]> wrote:

<snipped>

>this is the code the client is using to make the connection to the servlet.
>
>        String path ="http://www22.addr.com/~mgardne/servlets/ScrapBookServer";;
>        URL servletURL = new URL(path);
>        URLConnection connection = servletURL.openConnection();
>        connection.setUseCaches(false);
>
>      connection.setRequestProperty("CONTENT_TYPE","application/octet-stream");
>        connection.setDoInput(true);
>        connection.setDoOutput(true);
>        //make request
>        OutputStream out = connection.getOutputStream();
>        InputStream in = connection.getInputStream();
>        DataOutputStream dataOut = new DataOutputStream(out);
>        dataOut.writeInt(ScrapBookProtocol.GETSCRAPBOOK );
>        out.flush();
>        out.close();
>        //read response
>        DataInputStream dataIn = new DataInputStream(in);
>        int vc = dataIn.readInt(); //**exception occurs here!!
>        System.out.println("Validation Code Received: " + vc);
>
>When I run the client side program I get a java.io.EOFException, at the call
>to dataIn.readInt(), which seems to indicate that the server isn't sending
>anything back.
>Also, the call to toLog() should write the integer that the client sent to a
>log file, and
>nothing is getting written there. So, I'm either not making a connection at
>all, or the
>Servlet is not sending anything back.  Am I missing anything here?  What is
>the correct way
>of sending integers back and forth between a program and a servlet??

There seems to be one problem with the code above.
When you do the setDoOutput(true), the code will set the request type to POST. Now 
when you send a post request, you have to specify the content-length header, which 
tells about the length of the data in the body of the request.

You will need to write the data to a buffer, check the length of the data that you are 
sending and set it as a value of the content-length header.
The psedo code might be like.

byte[] dataToBeSent;
int length = dataToBeSent.length;
connection.setRequestProperty("CONTENT-LENGTH",Integer.toString(length));

Then your code should work fine.

Regds,
Gokul


>
>--Monte Glenn Gardner

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to