home *** CD-ROM | disk | FTP | other *** search
- Save Format v2.3(19971110)
- @begin Form "Form_Server"
-
- @begin Object "Powersoft Java AWT 1.10::java.applet.Applet"
- DesignName Form_Server;
- @begin ClassProperties
- @begin-code BaseClassList
-
- extends java.applet.Applet
-
- @end-code;
- @end;
- @begin Properties
- @begin DesignProperties
- Style "cf0000";
- DesignRect 13,51,365,203;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- LayoutManager "powersoft.powerj.ui.ResizePercentageLayout";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @begin Events
- @begin Event "powersoft.powerj.event.Object.objectCreated"
- @begin-code SourceCode "powersoft.powerj.event.Object.objectCreated"
-
- public boolean Form_Server_objectCreated(powersoft.powerj.event.EventData event)
- {
- textf_1.setText( String.valueOf( DEFAULT_PORT ) );
- cb_2.requestFocus();
-
- return false;
- }
-
- /*
- *********************************************************************
- The Server object sets up a ServerSocket object running on its own
- thread. When the ServerSocket accepts a connection request a
- Connection object is created running on another thread. The Connection
- object manages i/o with the client side.
- *********************************************************************
- */
- public class Server extends Thread {
-
- ServerSocket listeningSocket;
-
- public Server( int port ) {
- if( port < 0 ) port = DEFAULT_PORT;
- try {
- listeningSocket = new ServerSocket( port );
- } catch( IOException e ) {
- _dbLog.log( "IOException while creating ServerSocket" );
- System.exit(1);
- }
- String msg = "Server is listening on port " + port;
- lb_1.add( msg );
- start();
- }
-
- public void run() {
- Socket clientSocket;
- Connection c;
- try {
- for(;;) {
- // Accept a connection request.
- // This blocks until a request is made.
- clientSocket = listeningSocket.accept();
- lb_1.add( "Client socket successfully created on server." );
- c = new Connection( clientSocket );
- String msg = "Connected to " + clientSocket.getInetAddress().getHostName();
- lb_1.add( msg );
- }
- } catch( IOException e ) {
- _dbLog.log ( "IOException while listening for connection requests!" );
- }
- }
- }
-
- class Connection extends Thread {
- DataInputStream input;
- PrintStream output;
- Socket localClientSocket;
-
- public Connection( Socket clientSocket ) {
- localClientSocket = clientSocket;
- try {
- input = new DataInputStream( localClientSocket.getInputStream() );
- output = new PrintStream( localClientSocket.getOutputStream() );
- } catch( IOException e) {
- _dbLog.log( "IOException while creating socket IO streams!" );
- return;
- }
- start();
- }
-
- public void run() {
- String line;
- String msg;
-
- try {
- for(;;) {
- // Blocks waiting for input from client side socket.
- line = input.readLine();
- if( line == null ) break;
- msg = "Message received: " + "\"" + line + "\"";
- lb_1.add( msg );
- msg = msg + " Thank you";
- output.println( msg );
- }
- } catch( IOException e ) {
- _dbLog.log( "IOException while listening for input!" );
- } finally {
- try {
- localClientSocket.close();
- lb_1.add( "Connection terminated. Bye!" );
- } catch( IOException e ) {
- _dbLog.log( "IOException while closing client socket on server!" );
- }
- }
- }
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunctions
- @begin UserFunction "Form_Server()"
- @begin Definition
- @begin-code SourceCode "Form_Server()"
-
- public Form_Server()
- {
- super();
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunction "processEvent(java.awt.AWTEvent event)"
- @begin Definition
- @begin-code SourceCode "processEvent(java.awt.AWTEvent event)"
-
- public void processEvent(java.awt.AWTEvent event)
- {
-
- defaultProcessEvent(event);
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunction "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
- @begin Definition
- @begin-code SourceCode "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
-
- public void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
- {
-
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunction "getContentPane()"
- @begin Definition
- @begin-code SourceCode "getContentPane()"
-
- public java.awt.Container getContentPane()
- {
- return this;
- }
-
- @end-code;
- @end;
- @end;
- @end;
- @begin CodeBlocks
- @begin CodeBlock "HppPrefix"
- FunctionScope 1;
- @begin-code SourceCode "Imports()"
-
- // add your custom import statements here
- import java.net.*;
- import java.io.*;
-
- @end-code;
- @end;
- @begin CodeBlock "ClassContents"
- FunctionScope 1;
- @begin-code SourceCode "Data Members()"
-
- // add your data members here
- public static final int DEFAULT_PORT = 1777;
-
- powersoft.powerj.util.Debug _dbLog;
-
- @end-code;
- @end;
- @begin CodeBlock "GeneratedClassContents"
- FunctionScope 1;
- GeneratedFunction 1;
- @begin-code SourceCode "Not Applicable for Java()"
-
-
- @end-code;
- @end;
- @begin CodeBlock "CppPrefix"
- FunctionScope 1;
- GeneratedFunction 1;
- @begin-code SourceCode "Not Applicable for Java()"
-
-
- @end-code;
- @end;
- @end;
- @begin Objects
- @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
- DesignName cb_2;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- DesignRect 300,5,55,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- label "Start";
- @end;
- @end;
- @begin Events
- @begin Event "java.awt.event.Action.actionPerformed"
- @begin-code SourceCode "java.awt.event.Action.actionPerformed"
-
- public void cb_2_actionPerformed( java.awt.event.ActionEvent event )
- {
- Server s;
- Integer port = new Integer( textf_1.getText() );
-
- _dbLog = new powersoft.powerj.util.Debug();
- s = new Server( port.intValue() );
- }
-
- @end-code;
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
- DesignName textf_1;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 1;
- DesignRect 70,20,35,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.white";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.List"
- DesignName lb_1;
- @begin Properties
- @begin DesignProperties
- ResID 0;
- TabIndex 2;
- DesignRect 5,55,350,120;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.white";
- SerializationData "";
- @end;
- @begin ComponentProperties "lb_1"
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_1;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 3;
- DesignRect 5,40,85,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Server message log:";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_2;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 4;
- DesignRect 5,20,65,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Port to listen on:";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_3;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 5;
- DesignRect 5,5,250,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Specify the port to listen on for connection requests, then click Start";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @end;
- @end;
- @end;
-