CSDNU1234 2022-10-06 21:24 采纳率: 0%
浏览 34
已结题

talk小程序的驱动

这是一个talk的程序的驱动程序

package main.java;

import java.io.IOException;

/** Driver class for the Talk socket application. */
public class Talk {

  /**
   * The program behaves as a client with the specified client connection.
   * @param client the client interface to use for socket communication
   * @return {@code false} if the host is not available
   * @throws never should return {@code false} rather than throwing an exception
   */
  protected boolean clientMode(BasicTalkInterface client) {
    
    //任务return FALSE 如果host 不可用

    return false;
  }

  /**
   * The program behaves as a server with the specified server.
   * @param server the server interface to use for socket communication
   * @return {@code false} if the port is not available
   * @throws never should return {@code false} rather than throwing an exception
   */
  protected boolean serverMode(BasicTalkInterface server) {

    //任务return FALSE 如果host 不可用

    return false;
  }

  /**
   * The program enters auto mode and behaves as a client attempting to connect to the specified
   * host on the specified port. If the host is not available, the program should behave as a
   * server listening for connections on the specified port.
   * @param hostname the host to connect to
   * @param portnumber the port to connect to or listen on
   * @return {@code false} if the host and port are both unavailable
   * @throws never should return {@code false} rather than throwing an exception
   */
  public boolean autoMode(String hostname, int portnumber) {

    //任务call clientMode and serverMode
    
    return false;
  }

  /**
   * The program behaves as a client connecting to the specified host on the specified port.
   * @param hostname the host to connect to
   * @param portnumber the port to connect to
   * @return {@code false} if the host is not available
   * @throws never should return {@code false} rather than throwing an exception
   */
  public boolean clientMode(String hostname, int portnumber) {
    try {
      return this.clientMode(new TalkClient(hostname, portnumber));
    } catch (IOException e) {
      return false;
    }
  }

  /**
   * Should print your name and instructions on how to use the talk program. Instructions must
   * at least include the line "Talk [-a | –h | -s] [hostname | IPaddress] [–p portnumber]"
   */
  public void helpMode() {

    // 
  }

  /**
   * The program behaves as a server listening for connections on the specified port.
   * @param portnumber the port to listen for connections on
   * @return {@code false} if the port is unavailable
   * @throws never should return {@code false} rather than throwing an exception
   */
  public boolean serverMode(int portnumber) {
    try {
      return this.serverMode(new TalkServer(portnumber));
    } catch (IOException e) {
      return false;
    }
  }

  /**
   * Parses the specified args and executes the talk program in its intended mode.
   * @param args the CLI args
   * @throws never should return {@code false} rather than throwing an exception
   */
  public boolean start(String[] args) {
    
    // 任务调出autoMode, clientMode, helpMode, and serverMode
    return false;
  }

  public static void main(String[] args) {
    System.exit(new Talk().start(args) ? 0 : 1);
  }
}


  • 写回答

1条回答 默认 最新

  • 游一游走一走 2022-10-06 22:52
    关注
    java main.java.Talk -s 127.0.0.1 -p 8888
    java main.java.Talk -c 127.0.0.1 -p 8888
    
    package main.java;
    
    import java.io.IOException;
    import java.util.Arrays;
    
    /**
     * Driver class for the Talk socket application.
     */
    public class Talk {
    
        /**
         * The program behaves as a client with the specified client connection.
         *
         * @param client the client interface to use for socket communication
         * @return {@code false} if the host is not available
         * @throws never should return {@code false} rather than throwing an exception
         */
        protected boolean clientMode(BasicTalkInterface client) {
    
            //任务return FALSE 如果host 不可用
    
            return false;
        }
    
        /**
         * The program behaves as a server with the specified server.
         *
         * @param server the server interface to use for socket communication
         * @return {@code false} if the port is not available
         * @throws never should return {@code false} rather than throwing an exception
         */
        protected boolean serverMode(BasicTalkInterface server) {
    
            //任务return FALSE 如果host 不可用
    
            return false;
        }
    
        /**
         * The program enters auto mode and behaves as a client attempting to connect to the specified
         * host on the specified port. If the host is not available, the program should behave as a
         * server listening for connections on the specified port.
         *
         * @param hostname   the host to connect to
         * @param portnumber the port to connect to or listen on
         * @return {@code false} if the host and port are both unavailable
         * @throws never should return {@code false} rather than throwing an exception
         */
        public boolean autoMode(String hostname, int portnumber) {
    
            //任务call clientMode and serverMode
    
            return false;
        }
    
        /**
         * The program behaves as a client connecting to the specified host on the specified port.
         *
         * @param hostname   the host to connect to
         * @param portnumber the port to connect to
         * @return {@code false} if the host is not available
         * @throws never should return {@code false} rather than throwing an exception
         */
        public boolean clientMode(String hostname, int portnumber) {
            try {
                return this.clientMode(new TalkClient(hostname, portnumber));
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
    
        /**
         * Should print your name and instructions on how to use the talk program. Instructions must
         * at least include the line "Talk [-a | –h | -s] [hostname | IPaddress] [–p portnumber]"
         */
        public void helpMode() {
    
            //
        }
    
        /**
         * The program behaves as a server listening for connections on the specified port.
         *
         * @param portnumber the port to listen for connections on
         * @return {@code false} if the port is unavailable
         * @throws never should return {@code false} rather than throwing an exception
         */
        public boolean serverMode(int portnumber) {
            try {
                return this.serverMode(new TalkServer(portnumber));
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
    
        /**
         * Parses the specified args and executes the talk program in its intended mode.
         *
         * @param args the CLI args
         * @throws never should return {@code false} rather than throwing an exception
         */
        public boolean start(String[] args) {
            String remoteHost = args[1];
            String remotePort = args[3];
            if ("-s".equals(args[0])) {
                serverMode(Integer.parseInt(remotePort));
            } else {
                clientMode(remoteHost, Integer.parseInt(remotePort));
            }
            // 任务调出autoMode, clientMode, helpMode, and serverMode
            return true;
        }
    
        public static void main(String[] args) {
            new Talk().start(args);
        }
    }
    
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 10月14日
  • 创建了问题 10月6日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog