Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/ciphercore/ClientDemo.java


1   /* $Id: ClientDemo.java,v 1.2 2001/03/20 00:51:19 cvsbob Exp $ */
2   
3   /*
4    * ClientDemo.java, simple example of a ciphercore client.
5    * Copyright (C) 2001 Robert Bushman.
6    *
7    * I reserve the right to release this program under seperate license.
8    * If you require a special license grant contact Robert Bushman.
9    *
10   * This program is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU General Public License
12   * as published by the Free Software Foundation; either version 2
13   * of the License, or (at your option) any later version.
14   *
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Public License
21   * along with this program; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
23   * 02111-1307, USA.
24   */
25  
26  package com.ciphercore;
27  
28  import java.io.DataInputStream;
29  import java.io.DataOutputStream;
30  import java.io.IOException;
31  
32  public class ClientDemo {
33      
34      public static void main( String[] args ) throws IOException {
35          Client client = new Client( "com.ciphercore.ChildDemo",
36                                      "localhost",
37                                      5943 );
38          client.connect();
39          commDemo( client );
40      }
41      
42      public static void commDemo( Client client ) {
43          System.out.println( "Entering Comm Demo" );
44          try {
45              DataInputStream in =
46                  new DataInputStream( client.getBaseInputStream() );
47              DataOutputStream out =
48                  new DataOutputStream( client.getBaseOutputStream() );
49              
50              String testString = "This is Major Tom to ground control.";
51              
52              out.writeInt( 6400 );
53              out.writeInt( testString.getBytes().length );
54              out.write( testString.getBytes() );
55              out.writeInt( 3200 );
56              out.flush();
57              
58              System.out.println( "int 1: " + in.readInt() );
59              int testStringLength = in.readInt();
60              System.out.println( "Test String Length: " + testStringLength );
61              byte[] testStringBytes = new byte[ testStringLength ];
62              in.readFully( testStringBytes );
63              System.out.println
64                  ( "Test String: " + new String( testStringBytes ) );
65              System.out.println( "int 2: " + in.readInt() );
66          } catch( IOException e ) {
67              e.printStackTrace();
68              System.exit( 1 );
69          }
70      }
71  }
72