Do not flush and close the 'out' stream.
flush and close 'dataOut'. By instantiating dataOut with out you hand
over control of out to dataOut.
Peter
----- Original Message -----
From: Gardner Monte <[EMAIL PROTECTED]>
Date: Thursday, November 29, 2001 0:05 am
Subject: Bouncing Integers
> I'm trying to write an application consisting of a
> client side application and a Server side Servlet.
> To start out, the client is supposed to send an
> integer to the Servlet, and then the
> Servlet is supposed to send an Integer back.
>
>
> this is the important part of the service method my Servlet is using
>
>
> OutputStream out = response.getOutputStream();
> InputStream in = request.getInputStream();
> DataInputStream dataIn = new DataInputStream(in);
> DataOutputStream dataOut = new DataOutputStream(out);
> int requesttype;
> requesttype = dataIn.readInt();
> //write the integer received to a file
> tolog("Request : " + requesttype);
> dataOut.writeInt(ScrapBookProtocol.VALID);
>
>
> 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
> sendinganything 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??
>
>
>
> --Monte Glenn Gardner
>
>
________________________________________________________________________
___
> To unsubscribe, send email to [EMAIL PROTECTED] and include in
> the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http:
> Resources: http://java.sun.com/products/servlet/external-
> resources.htmlLISTSERV Help:
> http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
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