FileDocCategorySizeDatePackage
ChargenClient.javaAPI DocExample955Sun Dec 12 10:53:30 GMT 2004None

ChargenClient

public class ChargenClient extends Object

Fields Summary
public static int
DEFAULT_PORT
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  
       
  
    if (args.length == 0) {
      System.out.println("Usage: java ChargenClient host [port]"); 
      return;
    }  
  
    int port;
    try {
      port = Integer.parseInt(args[1]);
    }
    catch (Exception ex) {
      port = DEFAULT_PORT;   
    }
    
    try {
      SocketAddress address = new InetSocketAddress(args[0], port);
      SocketChannel client = SocketChannel.open(address);
      
      ByteBuffer buffer = ByteBuffer.allocate(74);
      WritableByteChannel out = Channels.newChannel(System.out);
      
      while (client.read(buffer) != -1) {
        buffer.flip();
        out.write(buffer);
        buffer.clear();
      }     
    }
    catch (IOException ex) {
        ex.printStackTrace();   
    }