예제 #1
0
  /** Create the serversocket and use its stream to receive serialized objects */
  public static void main(String args[]) {

    ServerSocket ser = null;
    Socket soc = null;
    String str = null;
    Date d = null;

    try {
      ser = new ServerSocket(8020);
      /*
       * This will wait for a connection to be made to this socket.
       */
      soc = ser.accept();
      InputStream o = soc.getInputStream();
      ObjectInput s = new ObjectInputStream(o);
      str = (String) s.readObject();
      d = (Date) s.readObject();
      s.close();

      // print out what we just received
      System.out.println(str);
      System.out.println(d);
    } catch (Exception e) {
      System.out.println(e.getMessage());
      System.out.println("Error during serialization");
      System.exit(1);
    }
  }
예제 #2
0
 private void readFromObjectInput(String filename) {
   try {
     URL url = new URL(getCodeBase(), filename);
     InputStream stream = url.openStream();
     ObjectInput input = new ObjectInputStream(stream);
     fDrawing.release();
     fDrawing = (Drawing) input.readObject();
     view().setDrawing(fDrawing);
   } catch (IOException e) {
     initDrawing();
     showStatus("Error: " + e);
   } catch (ClassNotFoundException e) {
     initDrawing();
     showStatus("Class not found: " + e);
   }
 }