Beispiel #1
0
  /**
   * It gets the length of the key
   *
   * @param key specify the key whose length will be calculated. Input parameter.
   * @return return the length of the key
   * @exception KeyNotMatchException key is neither StringKey nor IntegerKey
   * @exception IOException error from the lower layer
   */
  protected static final int getKeyLength(KeyClass key) throws KeyNotMatchException, IOException {
    if (key instanceof StringKey) {

      OutputStream out = new ByteArrayOutputStream();
      DataOutputStream outstr = new DataOutputStream(out);
      outstr.writeUTF(((StringKey) key).getKey());
      return outstr.size();
    } else if (key instanceof IntegerKey) return 4;
    else throw new KeyNotMatchException(null, "key types do not match");
  }
  public void initilize2() {
    int i;
    msg = s2.toCharArray();
    for (i = 0; i < s2.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.print(msg[i]);
      } catch (Exception e) {
        System.out.print("init 2 send" + e);
      }
    }

    try {

      while ((rs = dis.readLine()) != null) {
        // System.out.println(rs);
        if (rs.equals("OK")) {
          break;
        }
        if (rs.equals("ERROR")) {
          break;
        }
      }

    } catch (Exception e) {
      System.out.println("init 2 rec" + e);
    }
  }
Beispiel #3
0
 public synchronized void send(String msg) {
   try {
     streamOut.writeUTF(msg);
   } catch (IOException ioe) {
     System.err.println("Sending error: " + ioe.getMessage());
     System.exit(0);
   }
 }
Beispiel #4
0
 public void stop() {
   try {
     if (streamOut != null) streamOut.close();
     if (socket != null) socket.close();
   } catch (IOException ioe) {
     System.err.println("Error closing ...");
     System.exit(0);
   }
   loginThread.close();
 }
 public void connectionclose() {
   try {
     is.close();
     os.close();
     dis.close();
     dos.close();
     sPort.close();
   } catch (Exception e) {
     System.out.println("close" + e);
   }
 }
Beispiel #6
0
  private void SignInButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_SignInButtonActionPerformed

    /* username i password spojit u jedan string s delimiterom " ",
        prije toga nadodat kljucnu rijec "log"
        taj string se parsira na strani servera i server provjerava jel zadovoljava username i password
        (odgovor od servera slusa LoginThread koji salje odgovor Login-u preko handle metode)
    */
    String username = UsernameLogin.getText();
    String password = PasswordLogin.getText();
    String user_pass = "******" + " " + username + " " + password;

    try {
      streamOut.writeUTF(user_pass);
    } catch (IOException ioe) {
      System.err.println("Sending error: " + ioe.getMessage());
      System.exit(0);
    }
  } // GEN-LAST:event_SignInButtonActionPerformed
  public void read() {
    int i, j, k;
    String temp = "";
    String temp1 = "";

    msg = s3.toCharArray();
    for (i = 0; i < s3.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.println(msg[i]);
      } catch (Exception e) {
        System.out.print("read send" + e);
      }
    }
    try {
      while ((rs = dis.readLine()) != null) {
        temp += rs;
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
      }

      k = 0;
      StringTokenizer t = new StringTokenizer(temp, "\"");
      while (t.hasMoreTokens()) {
        temp1 = "" + t.nextToken().trim();
        k++;
        if (k == 7) {
          System.out.println(temp1);
          VoiceManager voiceManager = VoiceManager.getInstance();
          Voice helloVoice = voiceManager.getVoice("kevin");
          helloVoice.allocate();
          helloVoice.speak(temp1);
          helloVoice.deallocate();
        }
      }

    } catch (Exception e) {
      System.out.print("read rec" + e);
    }
  }
  public void delete() {
    int i;
    msg = s4.toCharArray();
    try {
      for (i = 0; i < s4.length(); i++) {
        dos.write(msg[i]);
        System.out.print(msg[i]);
      }

    } catch (Exception e) {
      System.out.print("del send" + e);
    }
    try {
      while ((rs = dis.readLine()) != null) {
        System.out.println(rs);
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
        if (rs.equals("+CMS ERROR: 321")) break;
      }
    } catch (Exception e) {
      System.out.print("del rec" + e);
    }
  }
Beispiel #9
0
 // =========================================================
 public void send(String strToSend) throws IOException // SEND METHOD
     {
   dos.writeBytes(strToSend + '\n');
   System.out.println("SENT>>>> " + id + ": " + strToSend);
 }