Package commoms

Examples of commoms.CommandIF


 
    synchronized (outputStreams) {
      // Tell the world
      log.error("Removing connection to " + senderName);
 
      CommandIF comm = updateRemovedPeerList(senderName, s);
      outputStreams.remove(s);
      // Make sure it's closed
      try {
        s.close();
      } catch (IOException ie) {
View Full Code Here


      //don't do anything
    }
    if (!peers.containsKey(userId)) {
      peers.put(userId, store);
      // send message to all.
      CommandIF comm = makeCommandOfPeerList();
      comm.setMessage(userId + " joined in!");
      sendToAll(comm);
    }// if
  }
View Full Code Here

  // while removing
  CommandIF updateRemovedPeerList(String userName, Socket store) {

    peers.remove(userName);

    CommandIF comm = makeCommandOfPeerList();
    comm.setMessage(" " + userName + " gone away!");
    return comm;
  }
View Full Code Here

      // is using a ObjectOutputStream to write to us
      din = new ObjectInputStream(socket.getInputStream());
      // Over and over, forever ...
      while (true) {
    // ... read the next message ...
    CommandIF comm = null;
    try {
        comm = (CommandIF) din.readObject();

    } catch (ClassNotFoundException e) {
        log
          .error("Class cast breaking up. Try some packaging stuff");
        e.printStackTrace();
    } catch (IOException ioe) {
        // seems like socket is reset
        // lets update list
        // server.removeConnection(senderName, socket);
    }
    // ... tell the world ...
    server.updatePeerList(comm, socket);
    /*
     * extraction
     */
    String message = comm.getMessage();
    System.out.println("Sending " + message);
    String pureMessage = message;

    InetAddress inet = socket.getInetAddress();
    String sock = inet.getHostAddress();

    senderName = comm.getMsgFrom();
    ServerThread.verifyList(senderName);
    tracer.tracerDb(sock, comm.getMsgFrom(), pureMessage, comm
      .getRecipientNames());
    // ... and have the server send it to all clients
    if (comm.getCommand().equals(ProtocolConstants.COMMAND_SEND)) {
        if (comm.getRecipientNames().get(0).equals(
          ProtocolConstants.SEND_TO_ALL)) {
      server.sendToAll(comm);
        } else {
      // surely user is trying to send message but not to all
      // peers
      if (!comm.isSendingFile()) {
          server.sendToAll(comm);
      } else {
          // user is trying to send file

          CommandIF fileCommand = handleFileRequest(comm);
          server.sendToAll(fileCommand);
      }
        }
    } else if (comm.getCommand().equals(
      ProtocolConstants.DELETE_FILE)) {
View Full Code Here

      // is using a DataOutputStream to write to us
      ObjectInputStream din = new ObjectInputStream(socket.getInputStream());
      // Over and over, forever ...
      while (true) {
        // ... read the next message ...
        CommandIF comm = null;
        try {
          comm = (CommandIF)din.readObject();
        } catch (ClassNotFoundException e) {
          log.error("Class cast breaking up. Try some packaging stuff");
          e.printStackTrace();
        } catch (IOException ioe) {
          // seems like socket is reset
          // lets update list
          //server.removeConnection(senderName, socket);
           }
        // ... tell the world ...
        server.updatePeerList(comm, socket);
        /*
         * extraction
         */
        String message = comm.getMessage();
        System.out.println("Sending " + message);
        int i = message.indexOf(":");
        String pureMessage = message.substring(i);

        // String sock = socket.toString();
        InetAddress inet = socket.getInetAddress();
        String sock = inet.getHostAddress();
        senderName = message.substring(0, i).trim();
        ServerThread.verifyList(senderName);
        tracer.tracerDb(sock, comm.getMsgFrom(), pureMessage, comm.getRecipientNames());
        // ... and have the server send it to all clients
        if(comm.getCommand().equals(ProtocolConstants.COMMAND_SEND)) {
           if(comm.getRecipientNames().get(0).equals(ProtocolConstants.SEND_TO_ALL)) {
             server.sendToAll(comm);
           } else {
             // surely user is trying to send message but not to all peers
             //TODO see if message sending can be limited to selected peers.
             server.sendToAll(comm);
View Full Code Here

    public synchronized void run() {

  try {

      CommandIF comm = null;
      while (true) {

    comm = (CommandIF) ois.readObject();

    if (comm.getCommand().equals(ProtocolConstants.COMMAND_SEND)) {
        boolean show = (!comm.isPrivateMessage())
          || comm.getMsgFrom().equals(sendername);
        Iterator itr = comm.getRecipientNames().iterator();
        boolean flag = false;
        mess = comm.getMessage();
        while (itr.hasNext()) {
      if (itr.next().toString().equals(sendername)) {
          flag = true;

      }
        }
        show = show || flag;
        if (show) {

      red.updateMsg(comm);
        }
    }// if

    // for updating peer list.
    if (comm.getCommand()
      .equals(ProtocolConstants.UPDATE_PEER_LIST)) {
        cap.updateUsersList(comm);
    }// if

    if (comm.getCommand().equals(ProtocolConstants.DOWNLOAD_FILE) && comm.getRecipientNames().contains(sendername)) {
        showFileAlert(comm);
       
       
        if (cap.acceptFile && downloadFile(comm)) {
      cap.saveMsg.setText("Saved file " + System.getProperty("user.home") + File.separator + comm.getFileName());
      cap.ssm.setVisible(true);     
      cap.userPressed = false;
      cap.acceptFile = false;
      accept_reject = false;
      sendDeleteFileCommand(comm);
View Full Code Here

TOP

Related Classes of commoms.CommandIF

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.