コード例 #1
0
 protected void stopRequested() {
   try {
     if (!server.isClosed()) {
       server.close();
     }
   } catch (IOException e) {
     // A least I have tried...
     // This is only to kick server.accept() out of its block - if there is a
     // problem, the accept has already failed
   }
 };
コード例 #2
0
  protected void doTask() throws Exception {
    while (stateCheck(STATECHECK_RUNNING)) {
      try {
        Socket client = server.accept();
        if (null != client) {
          ICShell clientShell = new ICShellSocket(client);

          LineProcessor processor;
          if (null != procNode) {
            processor =
                (ICShell.LineProcessor)
                    ICAppFrame.getComponent(procNode, ICShell.LineProcessor.class);
          } else {
            processor =
                new ICShellCmdProcessor(
                    (ICGenCommand) ICAppFrame.getComponent(APP_COMMANDS, ICGenCommand.class));
          }

          clientShell.setProcessor(processor);
          SocketAddress sa = client.getRemoteSocketAddress();
          clientShell.setName(getName() + " client connected from " + sa);
          clientShell.startShell();
        }
      } catch (SocketException ex) {
        // if the accept failed because stopRequested(), we should not throw exception
        if (stateCheck(STATECHECK_RUNNING)) {
          throw ex;
        }
      }
    }
  }