/** Initializes the controller class. */
 @Override
 public void initialize(URL url, ResourceBundle rb) {
   logger.entry();
   OkButton.disableProperty()
       .bind(
           Bindings.isEmpty(FederationExecutionName.textProperty())
               .or(Bindings.isEmpty(FederateType.textProperty())));
   logger.exit();
 }
Beispiel #2
0
 // Close socket and IO streams, change appearance/functionality of some components
 private void closeAll() throws IOException {
   displayArea.append("\nConnection closing");
   output.close();
   input.close();
   connection.close();
   // We are no longer connected
   connection = null;
   // Change components
   serverField.setEditable(true);
   connectButton.setLabel("Connect to server above");
   enterField.setEnabled(false);
 }
Beispiel #3
0
 public CipherChatClient() {
   super("Cipher Chat Client");
   // Establish keys for RSA cipher
   makeKeys();
   // Lay out the components and display the frame
   setLayout(new GridLayout(2, 1));
   top.setLayout(new GridLayout(3, 1));
   add(top);
   bottom.setLayout(new GridLayout(1, 1));
   add(bottom);
   connectButton.addActionListener(this);
   enterField.setEnabled(false);
   enterField.addActionListener(this);
   top.add(serverField);
   top.add(connectButton);
   top.add(enterField);
   bottom.add(displayArea);
   setSize(400, 300);
   show();
 }
Beispiel #4
0
  void showContent() {
    URL address = null;

    try {
      address = new URL(addressTextField.getText());
    } catch (MalformedURLException mue) {
      showWarning(mainFrame, "地址输入错误");
    }

    System.out.println("getProtocol() " + address.getProtocol());
    System.out.println("getHost() " + address.getHost());
    System.out.println("getPort() " + address.getPort());
    System.out.println("getPath() " + address.getPath());
    System.out.println("getFile() " + address.getFile());
    System.out.println("getQuery() " + address.getQuery());
  }
 public void updateStats() {
   // This just updates any statistics that are shown on the face of
   // the server window
   stats.setText(
       server.strings.get(thisClass, "connectionscurrent")
           + " "
           + server.currentConnections
           + "  "
           + server.strings.get(thisClass, "connectionspeak")
           + " "
           + server.peakConnections
           + "  "
           + server.strings.get(thisClass, "connectionstotal")
           + " "
           + server.totalConnections);
   return;
 }
Beispiel #6
0
 public void launchFrame() {
   setLocation(500, 200);
   this.setSize(100, 100);
   add(tfTxt, BorderLayout.SOUTH);
   add(taContent, BorderLayout.NORTH);
   pack();
   this.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           disconnect();
           System.exit(0);
         }
       });
   tfTxt.addActionListener(new TFListener());
   setVisible(true);
   connect();
 }
 @FXML
 private void Ok_click(ActionEvent event) {
   logger.entry();
   LogEntry log = new LogEntry("6.16", "Local Delete Object Instance service");
   try {
     ObjectInstanceHandle instanceHandle =
         rtiAmb
             .getObjectInstanceHandleFactory()
             .decode(
                 ByteBuffer.allocate(4)
                     .putInt(Integer.parseInt(ObjectInstanceDesignator.getText()))
                     .array(),
                 0);
     log.getSuppliedArguments()
         .add(
             new ClassValuePair(
                 "Object instance designator",
                 ObjectInstanceHandle.class,
                 instanceHandle.toString()));
     rtiAmb.localDeleteObjectInstance(instanceHandle);
     log.setDescription("Local Object instance deleted successfully");
     log.setLogType(LogEntryType.REQUEST);
   } catch (FederateNotExecutionMember
       | NotConnected
       | NumberFormatException
       | CouldNotDecode
       | RTIinternalError
       | OwnershipAcquisitionPending
       | FederateOwnsAttributes
       | ObjectInstanceNotKnown
       | SaveInProgress
       | RestoreInProgress ex) {
     log.setException(ex);
     log.setLogType(LogEntryType.ERROR);
     logger.log(Level.ERROR, ex.getMessage(), ex);
   } catch (Exception ex) {
     log.setException(ex);
     log.setLogType(LogEntryType.FATAL);
     logger.log(Level.FATAL, ex.getMessage(), ex);
   }
   logEntries.add(log);
   ((Stage) OkButton.getScene().getWindow()).close();
   logger.exit();
 }
Beispiel #8
0
  void addEvent() {
    mainFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    addressTextField.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();

            if (keyCode == KeyEvent.VK_ENTER) {
              showContent();
            }
          }
        });

    gotoButton.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();

            if (keyCode == KeyEvent.VK_ENTER) {
              showContent();
            }
          }
        });

    gotoButton.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            showContent();
          }
        });
  }
 /** Initializes the controller class. */
 @Override
 public void initialize(URL url, ResourceBundle rb) {
   logger.entry();
   OkButton.disableProperty().bind(ObjectInstanceDesignator.textProperty().isEmpty());
   logger.exit();
 }
  public babylonServerWindow(babylonServer parent, String Name) {
    super(Name);
    server = parent;

    myLayout = new GridBagLayout();
    setLayout(myLayout);

    p = new Panel();
    p.setLayout(myLayout);

    listening = new Label(server.strings.get(thisClass, "listenport") + " " + server.port);
    p.add(
        listening,
        new babylonConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    logChat = new Checkbox(server.strings.get(thisClass, "logchats"), server.logChats);
    logChat.addItemListener(this);
    p.add(
        logChat,
        new babylonConstraints(
            1,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    userList = new List(4, false);
    userList.addItemListener(this);
    p.add(
        userList,
        new babylonConstraints(
            0,
            1,
            1,
            5,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    userAdmin = new Button(server.strings.get(thisClass, "usermanagement"));
    userAdmin.addActionListener(this);
    p.add(
        userAdmin,
        new babylonConstraints(
            1,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    console = new Button(server.strings.get(thisClass, "adminclient"));
    console.addActionListener(this);
    p.add(
        console,
        new babylonConstraints(
            1,
            2,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    disconnect = new Button(server.strings.get(thisClass, "disconnectuser"));
    disconnect.setEnabled(false);
    disconnect.addActionListener(this);
    p.add(
        disconnect,
        new babylonConstraints(
            1,
            3,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    disconnectAll = new Button(server.strings.get(thisClass, "disconnectall"));
    disconnectAll.setEnabled(false);
    disconnectAll.addActionListener(this);
    p.add(
        disconnectAll,
        new babylonConstraints(
            1,
            4,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    shutdown = new Button(server.strings.get(thisClass, "shutdown"));
    shutdown.addActionListener(this);
    p.add(
        shutdown,
        new babylonConstraints(
            1,
            5,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    stats =
        new TextField(
            server.strings.get(thisClass, "connectionscurrent")
                + " 0  "
                + server.strings.get(thisClass, "connectionspeak")
                + " 0  "
                + server.strings.get(thisClass, "connectionstotal")
                + " 0",
            40);
    stats.setEditable(false);
    p.add(
        stats,
        new babylonConstraints(
            0,
            7,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    logWindow =
        new TextArea(
            server.strings.get(thisClass, "activitylog") + "\n",
            10,
            40,
            TextArea.SCROLLBARS_VERTICAL_ONLY);
    logWindow.setEditable(false);
    p.add(
        logWindow,
        new babylonConstraints(
            0,
            8,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    canvas = new babylonPictureCanvas(this);
    p.add(
        canvas,
        new babylonConstraints(
            0,
            9,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    add(
        p,
        new babylonConstraints(
            0,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    try {
      URL url = new URL("file", "localhost", "babylonPic.jpg");
      Image image = getToolkit().getImage(url);

      canvas.setimage(image);
    } catch (Exception e) {
      System.out.println(e);
    }

    try {
      URL iconUrl = new URL("file", "localhost", "babylonIcon.jpg");
      ImageIcon icon = new ImageIcon(iconUrl);
      this.setIconImage(icon.getImage());
    } catch (Exception e) {
      /* Not important */
    }

    addWindowListener(this);

    setSize(600, 600);
    pack();
  }
Beispiel #11
0
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    // Client pressed enter in the message entry field-send it
    if (source == enterField) {
      // Get the message
      message = e.getActionCommand();
      try {
        // Encipher the message
        if (message.length() > plaintextBlockSize)
          message = message.substring(0, plaintextBlockSize);
        byte[] ciphertext =
            Ciphers.RSAEncipherWSalt(message.getBytes(), BigIntegerMath.THREE, recipModulus, sr);
        // Send to the server
        output.write(ciphertext);
        output.flush();
        // Display same message in client output area
        displayArea.append("\n" + message);
        enterField.setText("");
      } catch (IOException ioe) {
        displayArea.append("\nError writing message");
      }
    } else if (source == connectButton) {
      if (connection != null) { // Already connected-button press now means disconnect
        try {
          // Send final message of 0
          byte[] lastMsg = new byte[1];
          lastMsg[0] = 0;
          output.write(Ciphers.RSAEncipherWSalt(lastMsg, BigIntegerMath.THREE, recipModulus, sr));
          output.flush();
          // close connection and IO streams, change some components
          closeAll();
        } catch (IOException ioe) {
          displayArea.append("\nError closing connection");
        }
      } else { // Not connected-connect
        // Get name of server to connect to
        chatServer = serverField.getText();
        displayArea.setText("Attempting connection to " + chatServer);
        try {
          // Set up the socket
          connection = new Socket(chatServer, 55555);

          displayArea.append("\nConnected to: " + connection.getInetAddress().getHostName());

          // Set up the IO streams
          output = new DataOutputStream(connection.getOutputStream());
          output.flush();
          input = new DataInputStream(connection.getInputStream());

          // Exchange public keys with the server-send yours, get theirs
          exchangeKeys();

          // Change appearance/functionality of some components
          serverField.setEditable(false);
          connectButton.setLabel("Disconnect from server above");
          enterField.setEnabled(true);
          // Set up a thread to listen for the connection
          listener =
              new Thread(
                  new Runnable() {
                    public void run() {
                      go();
                    }
                  });
          listener.start();
        } catch (IOException ioe) {
          displayArea.append("\nError connecting to " + chatServer);
        }
      }
    }
  }
Beispiel #12
0
 // ON SEND MAIL
 int onSendMail() {
   String inBuffer;
   String outBuffer;
   Socket sock;
   SMTPInputStream fromServer;
   SMTPOutputStream toServer;
   int intPort;
   // TEST RECIPIENT ADDRESS it must be at once
   if (reciverMail.getText().length() < 1) {
     infoArea.Println("enter recipient please ...");
     return -1;
   }
   // TEST PORT NUMBER FORMAT and ALERT WHEN NOT 25
   intPort = -1;
   infoArea.Clear();
   infoArea.Println("check port ...");
   try {
     intPort = Integer.valueOf(smtpPort.getText()).intValue();
     if ((intPort < 0) || (intPort > 65356)) {
       infoArea.Println("invalid port ...");
       return -1;
     }
     if (intPort != 25) infoArea.Println("attention port is not 25 ...");
     infoArea.Println("port number is " + smtpPort.getText());
   } catch (NumberFormatException e) {
     infoArea.Println("invalid port ...");
     return -1;
   }
   // CREATE SMTP CONNECTION
   infoArea.Println("connect to server ...");
   try {
     sock = new Socket(smtpServer.getText(), intPort);
   } catch (IOException e) {
     infoArea.Println("unable to connect(SK) ... " + e);
     return -1;
   }
   // CREATE SERVER STREAMS
   // INPUT STREAM
   try {
     fromServer = new SMTPInputStream(sock);
   } catch (IOException e) {
     infoArea.Println("unable to connect(IS) ...");
     return -1;
   }
   // OUTPUT STREAM
   try {
     toServer = new SMTPOutputStream(sock);
   } catch (IOException e) {
     infoArea.Println("unable to connect(OS) ...");
     return -1;
   }
   infoArea.Println("connected ...");
   // Mail Sending
   infoArea.Println("sending mail ...");
   // *******************************************************************
   try {
     int i = doSMTPTransaction(fromServer, toServer);
     if (i == 0) infoArea.Println("complete ...");
     else infoArea.Println("error ...");
   } catch (IOException e) {
     infoArea.Println("error ...");
   }
   // *******************************************************************
   // CLOSE SERVER STREAMS
   // OUTPUT STREAM
   infoArea.Println("disconnect from server ...");
   try {
     toServer.Close();
   } catch (IOException e) {
     infoArea.Println("alert OUTPUT STREAM ...");
   }
   // INPUT STREAM
   try {
     fromServer.Close();
   } catch (IOException e) {
     infoArea.Println("alert INPUT STREAM ...");
   }
   // CLOSE CONNECTION
   try {
     sock.close();
     infoArea.Println("disconnected ...");
   } catch (IOException e) {
     infoArea.Println("unable to disconnect ...");
     return -1;
   }
   return 0;
 }
  @FXML
  private void OK_click(ActionEvent event) {
    logger.entry();
    FederateHandle federateHandle;
    LogEntry log = new LogEntry("4.9", "Join Federation Execution service");
    try {
      if (!FederateName.getText().isEmpty()) {
        log.getSuppliedArguments()
            .add(new ClassValuePair("Federate Name", String.class, FederateName.getText()));
      }
      log.getSuppliedArguments()
          .add(new ClassValuePair("Federate Type", String.class, FederateType.getText()));
      log.getSuppliedArguments()
          .add(
              new ClassValuePair(
                  "Federation Execution Name", String.class, FederationExecutionName.getText()));
      List<URL> foms = new ArrayList<>();
      int i = 1;
      for (File file : FomModuleDesignators.getFiles()) {
        foms.add(file.toURI().toURL());
        log.getSuppliedArguments()
            .add(
                new ClassValuePair(
                    "FOM Module Deisgnator " + i++, URL.class, file.toURI().toURL().toString()));
      }
      if (FederateName.getText().isEmpty() && FomModuleDesignators.getFileNames().isEmpty()) {
        federateHandle =
            rtiAmb.joinFederationExecution(
                FederateType.getText(), FederationExecutionName.getText());
      } else if (FomModuleDesignators.getFileNames().isEmpty()) {
        federateHandle =
            rtiAmb.joinFederationExecution(
                FederateName.getText(), FederateType.getText(), FederationExecutionName.getText());
      } else if (FederateName.getText().isEmpty()) {
        federateHandle =
            rtiAmb.joinFederationExecution(
                FederateType.getText(),
                FederationExecutionName.getText(),
                foms.toArray(new URL[foms.size()]));
      } else {
        federateHandle =
            rtiAmb.joinFederationExecution(
                FederateName.getText(),
                FederateType.getText(),
                FederationExecutionName.getText(),
                foms.toArray(new URL[foms.size()]));
      }
      log.getReturnedArguments()
          .add(
              new ClassValuePair(
                  "Federate Handle", FederateHandle.class, federateHandle.toString()));
      log.setDescription("Federate joined federation execution successfully");
      log.setLogType(LogEntryType.REQUEST);
      logicalTimeFactory = rtiAmb.getTimeFactory();
      currentLogicalTime = logicalTimeFactory.makeInitial();

      // subscribe to HLAcurrentFDD to retrieve FDD
      ObjectClassHandle FederationHandle =
          rtiAmb.getObjectClassHandle("HLAobjectRoot.HLAmanager.HLAfederation");
      currentFDDHandle = rtiAmb.getAttributeHandle(FederationHandle, "HLAcurrentFDD");
      AttributeHandleSet set = rtiAmb.getAttributeHandleSetFactory().create();
      set.add(currentFDDHandle);
      rtiAmb.subscribeObjectClassAttributes(FederationHandle, set);
      rtiAmb.requestAttributeValueUpdate(FederationHandle, set, null);
      // In case of HLA_EVOKED we require this line to receive the FDD
      rtiAmb.evokeMultipleCallbacks(
          .05,
          1); // evoke one callback will not be enough because the reflect attribute is the second
              // one
    } catch (CouldNotCreateLogicalTimeFactory
        | CallNotAllowedFromWithinCallback
        | CouldNotOpenFDD
        | ErrorReadingFDD
        | InconsistentFDD
        | FederateNameAlreadyInUse
        | FederateAlreadyExecutionMember
        | FederationExecutionDoesNotExist
        | SaveInProgress
        | RestoreInProgress
        | NotConnected
        | RTIinternalError ex) {
      log.setException(ex);
      log.setLogType(LogEntryType.ERROR);
      logger.log(Level.ERROR, ex.getMessage(), ex);
    } catch (Exception ex) {
      log.setException(ex);
      log.setLogType(LogEntryType.FATAL);
      logger.log(Level.FATAL, ex.getMessage(), ex);
    }
    logEntries.add(log);
    ((Stage) FederationExecutionName.getScene().getWindow()).close();
    logger.exit();
  }
 @FXML
 private void Cancel_click(ActionEvent event) {
   logger.entry();
   ((Stage) FederationExecutionName.getScene().getWindow()).close();
   logger.exit();
 }