my question is:

the socket opened by client is closed by closing the InputStream associated
to it?

in other words, should I do socket.close() instead of in.close() in the
finally block?

Thanks!

public class DaytimeApplet extends Applet {

......

private String getDateUsingSocketText() {
    InputStream in = null;
    try {
      // Establish a socket connection with the servlet
      Socket socket = new Socket(getCodeBase().getHost(), getSocketPort());

      // Print an empty line, indicating we want the time as plain text
      PrintStream out = new PrintStream(socket.getOutputStream());
      out.println();
      out.flush();

      // Read the first line of the response
      // It should contain the current time
      in = socket.getInputStream();
      DataInputStream result =
        new DataInputStream(new BufferedInputStream(in));
      String date = result.readLine();

      // Return the retrieved string
      return date;
    }
    catch (Exception e) {
      // If there was a problem, print to System.out
      // (typically the Java console) and return null
      e.printStackTrace();
      return null;
    }
    finally {
      // Always close the connection
      // This code executes no matter how the try block completes
      if (in != null) {
        try { in.close(); }
        catch (IOException ignored) { }
      }
    }
  }

......

}


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

___________________________________________________________________________
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