/**
  * ** Writes the specified line to the specified socket's output stream ** @param socket The
  * socket which's output stream to write to ** @param val The line to write to the socket output
  * stream. A newline is ** appended if it does not already end with one. ** @throws IOException if
  * an error occurs
  */
 protected static void socketWriteLine(Socket socket, String val) throws IOException {
   if (val != null) {
     String lineTerm = ClientSocketThread.getLineTerminator();
     String v = val.endsWith(lineTerm) ? val : (val + lineTerm);
     ClientSocketThread.socketWriteBytes(socket, StringTools.getBytes(v), 0, -1);
   }
 }
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);
    String host = RTConfig.getString(ARG_HOST, null);
    int port = RTConfig.getInt(ARG_PORT, 0);

    /* send data */
    if (RTConfig.hasProperty(ARG_SEND)) {
      if (StringTools.isBlank(host)) {
        Print.logError("Target host not specified");
        usage();
      }
      if (port <= 0) {
        Print.logError("Target port not specified");
        usage();
      }
      String dataStr = RTConfig.getString(ARG_SEND, "hello");
      byte data[] =
          dataStr.startsWith("0x") ? StringTools.parseHex(dataStr, null) : dataStr.getBytes();
      ClientSocketThread cst = new ClientSocketThread(host, port);
      try {
        cst.openSocket();
        cst.socketWriteBytes(data);
      } catch (Throwable t) {
        Print.logException("Error", t);
      } finally {
        cst.closeSocket();
      }
      System.exit(0);
    }

    /* receive data */
    if (RTConfig.hasProperty(ARG_RECEIVE)) {
      if (port <= 0) {
        Print.logError("Target port not specified");
        usage();
      }
      if (!StringTools.isBlank(host)) {
        Print.logWarn("Specified 'host' will be ignored");
      }
      Print.logError("Receive not yet implemented ...");
      System.exit(99);
    }

    /* show usage */
    usage();
  }
Beispiel #3
0
 /**
  * ** Create a new instance of the specified class name ** @param className The class name to
  * instantiate ** @return The new instance of the specified class name
  */
 public static Object newInstance(String className)
     throws NoSuchMethodException, ClassNotFoundException, InstantiationException,
         IllegalAccessException {
   if (!StringTools.isBlank(className)) {
     // try {
     return Class.forName(className).newInstance();
     // } catch (InvocationTargetException ite) {
     //    Throwable th = ite.getCause();
     //    if (th == null) { th = ite; }
     //    throw th;
     // }
   } else {
     throw new ClassNotFoundException("Class name is null/blank");
   }
 }
 /**
  * ** Writes the specified String to the specified socket's output stream ** @param socket The
  * socket which's output stream to write to ** @param val The String to write to the socket output
  * stream. ** @throws IOException if an error occurs
  */
 protected static void socketWriteString(Socket socket, String val) throws IOException {
   if (val != null) {
     ClientSocketThread.socketWriteBytes(socket, StringTools.getBytes(val), 0, -1);
   }
 }