home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / samples.z / Form_Server.wxf < prev    next >
Encoding:
Text File  |  1998-03-25  |  9.4 KB  |  340 lines

  1. Save Format v2.3(19971110)
  2. @begin Form "Form_Server"
  3.  
  4.  @begin Object "Powersoft Java AWT 1.10::java.applet.Applet"
  5.   DesignName Form_Server;
  6.   @begin ClassProperties
  7. @begin-code BaseClassList
  8.  
  9. extends java.applet.Applet
  10.  
  11. @end-code;
  12.   @end;
  13.   @begin Properties
  14.    @begin DesignProperties
  15.     Style "cf0000";
  16.     DesignRect 13,51,365,203;
  17.    @end;
  18.    @begin ObjectProperties
  19.     font "Dialog-Plain-12";
  20.     LayoutManager "powersoft.powerj.ui.ResizePercentageLayout";
  21.     foreground "java.awt.Color.black";
  22.     background "java.awt.Color.lightGray";
  23.     SerializationData "";
  24.    @end;
  25.   @end;
  26.   @begin Events
  27.    @begin Event "powersoft.powerj.event.Object.objectCreated"
  28. @begin-code SourceCode "powersoft.powerj.event.Object.objectCreated"
  29.  
  30.     public boolean Form_Server_objectCreated(powersoft.powerj.event.EventData event)
  31.     {
  32.         textf_1.setText( String.valueOf( DEFAULT_PORT ) );
  33.         cb_2.requestFocus();
  34.  
  35.         return false;
  36.     }
  37.  
  38.     /*
  39.     *********************************************************************
  40.     The Server object sets up a ServerSocket object running on its own
  41.     thread.  When the ServerSocket accepts a connection request a
  42.     Connection object is created running on another thread. The Connection
  43.     object manages i/o with the client side.
  44.     *********************************************************************
  45.     */
  46.     public class Server extends Thread {
  47.  
  48.         ServerSocket        listeningSocket;
  49.  
  50.         public Server( int port ) {
  51.             if( port < 0 ) port = DEFAULT_PORT;
  52.             try {
  53.                 listeningSocket = new ServerSocket( port );
  54.             } catch( IOException e ) {
  55.                 _dbLog.log( "IOException while creating ServerSocket" );
  56.                 System.exit(1);
  57.             }
  58.             String msg = "Server is listening on port " + port;
  59.             lb_1.add( msg );
  60.             start();
  61.         }
  62.  
  63.         public void run() {
  64.             Socket          clientSocket;
  65.             Connection      c;
  66.             try {
  67.                 for(;;) {
  68.                     // Accept a connection request.
  69.                     // This blocks until a request is made.
  70.                     clientSocket = listeningSocket.accept();
  71.                     lb_1.add( "Client socket successfully created on server." );
  72.                     c = new Connection( clientSocket );
  73.                     String msg = "Connected to " + clientSocket.getInetAddress().getHostName();
  74.                     lb_1.add( msg );
  75.                 }
  76.             } catch( IOException e ) {
  77.                 _dbLog.log ( "IOException while listening for connection requests!" );
  78.             }
  79.          }
  80.     }
  81.  
  82.     class Connection extends Thread {
  83.         DataInputStream input;
  84.         PrintStream output;
  85.         Socket localClientSocket;
  86.  
  87.         public Connection( Socket clientSocket ) {
  88.             localClientSocket = clientSocket;
  89.             try {
  90.                 input = new DataInputStream( localClientSocket.getInputStream() );
  91.                 output = new PrintStream( localClientSocket.getOutputStream() );
  92.             } catch( IOException e) {
  93.                 _dbLog.log( "IOException while creating socket IO streams!" );
  94.                 return;
  95.             }
  96.             start();
  97.         }
  98.  
  99.         public void run() {
  100.             String line;
  101.             String msg;
  102.  
  103.             try {
  104.                 for(;;) {
  105.                     // Blocks waiting for input from client side socket.
  106.                     line = input.readLine();
  107.                     if( line == null ) break;
  108.                     msg = "Message received: " + "\"" + line + "\"";
  109.                     lb_1.add( msg );
  110.                     msg = msg + " Thank you";
  111.                     output.println( msg );
  112.                 }
  113.             } catch( IOException e ) {
  114.                 _dbLog.log( "IOException while listening for input!" );
  115.             } finally {
  116.                 try { 
  117.                     localClientSocket.close();
  118.                     lb_1.add( "Connection terminated. Bye!" );
  119.                 } catch( IOException e ) {
  120.                     _dbLog.log( "IOException while closing client socket on server!" );
  121.                 }
  122.             }
  123.         }
  124.     }
  125.  
  126. @end-code;
  127.    @end;
  128.   @end;
  129.   @begin UserFunctions
  130.    @begin UserFunction "Form_Server()"
  131.     @begin Definition
  132. @begin-code SourceCode "Form_Server()"
  133.  
  134.     public Form_Server()
  135.     {
  136.         super();
  137.     }
  138.  
  139. @end-code;
  140.     @end;
  141.    @end;
  142.    @begin UserFunction "processEvent(java.awt.AWTEvent event)"
  143.     @begin Definition
  144. @begin-code SourceCode "processEvent(java.awt.AWTEvent event)"
  145.  
  146.     public void processEvent(java.awt.AWTEvent event)
  147.     {
  148.  
  149.         defaultProcessEvent(event);
  150.     }
  151.  
  152. @end-code;
  153.     @end;
  154.    @end;
  155.    @begin UserFunction "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  156.     @begin Definition
  157. @begin-code SourceCode "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  158.  
  159.     public void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
  160.     {
  161.  
  162.     }
  163.  
  164. @end-code;
  165.     @end;
  166.    @end;
  167.    @begin UserFunction "getContentPane()"
  168.     @begin Definition
  169. @begin-code SourceCode "getContentPane()"
  170.  
  171.     public java.awt.Container getContentPane()
  172.     {
  173.         return this;
  174.     }
  175.  
  176. @end-code;
  177.     @end;
  178.    @end;
  179.   @end;
  180.   @begin CodeBlocks
  181.    @begin CodeBlock "HppPrefix"
  182.     FunctionScope 1;
  183. @begin-code SourceCode "Imports()"
  184.  
  185. // add your custom import statements here
  186. import java.net.*;
  187. import java.io.*;
  188.  
  189. @end-code;
  190.    @end;
  191.    @begin CodeBlock "ClassContents"
  192.     FunctionScope 1;
  193. @begin-code SourceCode "Data Members()"
  194.  
  195.     // add your data members here
  196.     public static final int DEFAULT_PORT = 1777;
  197.     
  198.     powersoft.powerj.util.Debug     _dbLog;
  199.  
  200. @end-code;
  201.    @end;
  202.    @begin CodeBlock "GeneratedClassContents"
  203.     FunctionScope 1;
  204.     GeneratedFunction 1;
  205. @begin-code SourceCode "Not Applicable for Java()"
  206.  
  207.  
  208. @end-code;
  209.    @end;
  210.    @begin CodeBlock "CppPrefix"
  211.     FunctionScope 1;
  212.     GeneratedFunction 1;
  213. @begin-code SourceCode "Not Applicable for Java()"
  214.  
  215.  
  216. @end-code;
  217.    @end;
  218.   @end;
  219.   @begin Objects
  220.    @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
  221.     DesignName cb_2;
  222.     @begin Properties
  223.      @begin DesignProperties
  224.       ResID 100;
  225.       DesignRect 300,5,55,14;
  226.      @end;
  227.      @begin ObjectProperties
  228.       font "Dialog-Plain-12";
  229.       foreground "java.awt.Color.black";
  230.       background "java.awt.Color.lightGray";
  231.       SerializationData "";
  232.       label "Start";
  233.      @end;
  234.     @end;
  235.     @begin Events
  236.      @begin Event "java.awt.event.Action.actionPerformed"
  237. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  238.  
  239.     public void cb_2_actionPerformed( java.awt.event.ActionEvent event )
  240.     {
  241.         Server          s;
  242.         Integer         port = new Integer( textf_1.getText() );
  243.         
  244.         _dbLog = new powersoft.powerj.util.Debug();
  245.         s = new Server( port.intValue() );       
  246.     }
  247.  
  248. @end-code;
  249.      @end;
  250.     @end;
  251.    @end;
  252.    @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
  253.     DesignName textf_1;
  254.     @begin Properties
  255.      @begin DesignProperties
  256.       ResID 100;
  257.       TabIndex 1;
  258.       DesignRect 70,20,35,14;
  259.      @end;
  260.      @begin ObjectProperties
  261.       font "Dialog-Plain-12";
  262.       foreground "java.awt.Color.black";
  263.       background "java.awt.Color.white";
  264.       SerializationData "";
  265.      @end;
  266.     @end;
  267.    @end;
  268.    @begin Object "Powersoft Java AWT 1.10::java.awt.List"
  269.     DesignName lb_1;
  270.     @begin Properties
  271.      @begin DesignProperties
  272.       ResID 0;
  273.       TabIndex 2;
  274.       DesignRect 5,55,350,120;
  275.      @end;
  276.      @begin ObjectProperties
  277.       font "Dialog-Plain-12";
  278.       foreground "java.awt.Color.black";
  279.       background "java.awt.Color.white";
  280.       SerializationData "";
  281.      @end;
  282.      @begin ComponentProperties "lb_1"
  283.      @end;
  284.     @end;
  285.    @end;
  286.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  287.     DesignName label_1;
  288.     @begin Properties
  289.      @begin DesignProperties
  290.       ResID 100;
  291.       TabIndex 3;
  292.       DesignRect 5,40,85,10;
  293.      @end;
  294.      @begin ObjectProperties
  295.       font "Dialog-Plain-12";
  296.       text "Server message log:";
  297.       foreground "java.awt.Color.black";
  298.       background "java.awt.Color.lightGray";
  299.       SerializationData "";
  300.      @end;
  301.     @end;
  302.    @end;
  303.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  304.     DesignName label_2;
  305.     @begin Properties
  306.      @begin DesignProperties
  307.       ResID 100;
  308.       TabIndex 4;
  309.       DesignRect 5,20,65,10;
  310.      @end;
  311.      @begin ObjectProperties
  312.       font "Dialog-Plain-12";
  313.       text "Port to listen on:";
  314.       foreground "java.awt.Color.black";
  315.       background "java.awt.Color.lightGray";
  316.       SerializationData "";
  317.      @end;
  318.     @end;
  319.    @end;
  320.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  321.     DesignName label_3;
  322.     @begin Properties
  323.      @begin DesignProperties
  324.       ResID 100;
  325.       TabIndex 5;
  326.       DesignRect 5,5,250,10;
  327.      @end;
  328.      @begin ObjectProperties
  329.       font "Dialog-Plain-12";
  330.       text "Specify the port to listen on for connection requests, then click Start";
  331.       foreground "java.awt.Color.black";
  332.       background "java.awt.Color.lightGray";
  333.       SerializationData "";
  334.      @end;
  335.     @end;
  336.    @end;
  337.   @end;
  338.  @end;
  339. @end;
  340.