testnwclient.java

来自「this is a trade sale system realized by 」· Java 代码 · 共 43 行

JAVA
43
字号
package trader.nw;
import java.io.*;
import java.net.*;

public class TestNwClient {
  public static void main(String args[]) {
    int port = 6001;
    int count = 0;
    Object obj = null;
    NwClient nwc;
    if (args.length > 0){
      try {
        port = Integer.parseInt(args[0]);
      } catch(Exception e) {
        System.out.println("TestNwClient " + e);
      }
    }
    nwc = new NwClient("localhost", port);
    try {
      while (true) {
        // send object
        obj = "message" + count++;
        try {
          nwc.send(obj);
        } catch(Exception e) {
          System.out.println("TestNwClient " + e);
        }
        // receive object
        obj = null;
        try {
          obj = nwc.receive();
          System.out.println("TestNwClient received " + obj);
        } catch(Exception e) {
          System.out.println("TestNwClient receive " + e);
        }
        Thread.sleep(4000);
      }
    } catch(Exception e) {
      System.out.println("TestNwClient: " + e);
    }
  }
}

⌨️ 快捷键说明

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