package examples.jdbc.informix4;

import java.applet.*;
import java.awt.*;   
import java.io.*;
import java.net.*;

/** 
 *
 *This simple example applet opens a socket on a given host and port
 * number.  It is a useful first test for your database connectivity
 * environment.  
 * <p> 
 * This example could fail if there is a firewall between your browser
 * and the given host. If this is the case, look for a proxy server to
 * help you get to the host.
 * <p> 
 * There may also be a problem with the browser's security
 * manager. Normal policy for a security manager is to let your applet
 * only connect to the host from which it loaded. Make sure your
 * applet is loaded from a web server on the same machine that hosts
 * your database. Using the Java utility <b>Appletviewer</b> allows the applet
 *to run without security restrictions.
 * <p> 
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=Package-examples.jdbc.informix4.html>Package examples.jdbc.informix4</a>.
 *<p>
 *<li> Change connection parameters to correspond to your Informix
 *Dynamic Server configuration.  If you need more help, check the section on
 *connecting to a database in the Developers Guide, <a
 *href=../../../classdocs/API_jinf4.html>Using WebLogic jDriver for Informix</a>.
 *
 *<p>
 *
 *<li>Compile this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ javac -d c:/weblogic/informix4/classes SocketApplet.java</b></font>
 *<p>	
 *
 *<li>Run this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ appletviewer SocketApplet.html</b></font>
 *
 *</ol>
 *
 *
 * <b>What should I do if this test fails?</b> 
 * <p> 
 * If this test fails, try to telnet directly to the database
 * server. From the command line type:
 * <pre> telnet hostname port </pre> 
 * <p> 
 * If you cannot telnet there's a chance that your database is not
 * there or there is a firewall between you and your database. If
 * telnet succeeds then you're probably having a problem with the Java
 * security manager.
 *<p>
 *
 *  @author Copyright (c) 1997-2000 by BEA Systems, Inc. All Rights Reserved.  
 **/

public class SocketApplet extends Applet
{

  // 
  // Change the host name of the database server (e.g. mycompany.com, or
  // server's IP address)
  //
    String host="myDBHost";

  // Database server port number. Check with your system administrator
  // which port the database is on. The default port for Informix
  // servers is 1493.

  int port = 1493;

  public void init()
  {
    try {
      Socket database = new Socket(host,port);
      database.close();
      message = "Success. Socket was opened.";
    }

    catch(Exception io) {
      message = "Exception while opening the socket on " + host + ":" + port + " " + io;
    }

    System.out.println(message);
    repaint();
  }

  public void paint(Graphics graphics)
  { 
    graphics.drawString(message,10,20);
  }
  
  String message = "";
}








