⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandclient.java

📁 some easy projects in java, can teach you basic project design method in java.
💻 JAVA
字号:
package trader.nw;
import java.io.*;
import java.net.*;
import trader.*;
import trader.db.*;

/** AddCommand and DeleteCommand UnitTest 2.
    Compile from classes directory
    javac -d . ../src/trader/nw/CommandClient.java

    In one terminal window start the CommandServer class
    java trader.nw.CommandServer

    In another terminal window start the CommandClient class
    java trader.nw.CommandClient
*/

class CommandClient {


  public static void main(String args[]) {
    String dbHost = "localhost";
    Command cmd;
    String id = "333_33_3333";

    Customer retCust;
    Object obj;

    System.out.println("CommandClient - AddCommand  " +
      "DelCommand Unit Test 2");
    try {
      if (args.length > 0) {
        dbHost = args[0];
      }
      NwClient client = new NwClient(dbHost, 6001);
      BrokerModel brokerModel = new BrokerModelDbImpl(dbHost);
      Thread.sleep(2000);
      while (true){
        try {
          System.out.println("Adding Customer " + id);
          Customer addCust = new Customer("333_33_3333",
            "Dough Nut", "Bakery Lane");
          Command addCmd = new AddCustomerCommand(addCust);
          client.send(addCmd);
          Thread.sleep(2000);
          cmd = (Command)client.receive();
          obj = cmd.getResult();
          Thread.sleep(5000);
        } catch(Exception e) {
          e.printStackTrace();
        }

        try {
          System.out.println("Getting Customer " + id);
          Command getCmd = new GetCustomerCommand(id);
          client.send(getCmd);
          Thread.sleep(2000);
          cmd = (Command)client.receive();
          System.out.println("Got Customer " +
            (Customer) cmd.getResult());
          Thread.sleep(5000);
        } catch(Exception e) {
          e.printStackTrace();
        }

        try {
          System.out.println("Deleting Customer " + id);
          Customer delCust = new Customer("333_33_3333",
            "Dough Nut", "Bakery Lane");
          Command delCmd = new DeleteCustomerCommand(delCust);
          client.send(delCmd);
          Thread.sleep(2000);
          cmd = (Command)client.receive();
          obj = cmd.getResult();
          Thread.sleep(5000);
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -