import java.io.*;
import java.net.*;
import java.applet.Applet;
import java.awt.Graphics;
import netscape.javascript.JSObject;

   public class EchoApplet extends Applet {
      String URIValue, SecuritiesList, SocketReturn;
      Socket echoSocket;
      PrintWriter out;
      BufferedReader in;
      BufferedReader stdIn;

      public void init() {
         System.err.println("Initing");

      }

      public void start() {

         System.err.println("Starting");
		  
         URIValue = getParameter("URIValue");
         try {
            echoSocket = new Socket("192.168.1.11", 7261);
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(
                                          echoSocket.getInputStream()));


            stdIn = new BufferedReader(
                                          new InputStreamReader(System.in));

            SecuritiesList =  getParameter("SecuritiesList");
            out.println(SecuritiesList);
            SocketReturn = in.readLine();

         } catch (UnknownHostException e) {
            System.err.println("Don't know about host: " + URIValue + " " + e);
            System.exit(1);
         } catch (IOException e) {
            System.err.println("Couldn't get I/O for "
                       + "the connection to: "+ URIValue + " " + e);
            System.exit(1);
         }


      }

      public void stop() {
		  
        try{

            out.close();
            in.close();
            stdIn.close();
            echoSocket.close();

         } catch (IOException e) {
            System.err.println("Couldn't get I/O. closing the connection to: "+ URIValue + " " + e);
            System.exit(1);
         }
      }

      public void destroy() {
      }
  
      public void paint(Graphics g) {
          //Draw a Rectangle around the applet's display area.
          g.drawRect(0, 0, size().width - 1, 5*size().height - 1);
//      g.setColor(blue);    
      g.drawString ("Content-type: text/html1010" , 5, 11);

          //Draw the current string inside the rectangle.
          g.drawString("URIValue = " + URIValue, 5, 15);
          g.drawString("SecuritiesList = " + SecuritiesList, 5, 20);
          g.drawString("SocketReturn = " + SocketReturn, 5, 25);
//Calling Javascript from applet
          JSObject win = JSObject.getWindow(this);
          String args2[] = {SocketReturn};
          win.call("popWinDemo", args2);

 
       }
    }






