public Socks5Message(int cmd,InetAddress ip,int port){
  super(cmd,ip,port);
  this.host=ip == null ? "0.0.0.0" : ip.getHostName();
  this.version=SOCKS_VERSION;
  byte[] addr;
  if (ip == null) {
    addr=new byte[4];
    addr[0]=addr[1]=addr[2]=addr[3]=0;
  }
 else   addr=ip.getAddress();
  addrType=addr.length == 4 ? SOCKS_ATYP_IPV4 : SOCKS_ATYP_IPV6;
  data=new byte[6 + addr.length];
  data[0]=(byte)SOCKS_VERSION;
  data[1]=(byte)command;
  data[2]=(byte)0;
  data[3]=(byte)addrType;
  System.arraycopy(addr,0,data,4,addr.length);
  data[data.length - 2]=(byte)(port >> 8);
  data[data.length - 1]=(byte)(port);
}

public Socks5Message ( int cmd , InetAddress ip , int port ) { super ( cmd , ip , port ) ; this . host = ip == null ? "0.0.0.0" : ip . getHostName ( ) ; this . version = SOCKS_VERSION ; byte [ ] addr ; if ( ip == null ) { addr = new byte [ 4 ] ; addr [ 0 ] = addr [ 1 ] = addr [ 2 ] = addr [ 3 ] = 0 ; } else addr = ip . getAddress ( ) ; addrType = addr . length == 4 ? SOCKS_ATYP_IPV4 : SOCKS_ATYP_IPV6 ; data = new byte [ 6 + addr . length ] ; data [ 0 ] = ( byte ) SOCKS_VERSION ; data [ 1 ] = ( byte ) command ; data [ 2 ] = ( byte ) 0 ; data [ 3 ] = ( byte ) addrType ; System . arraycopy ( addr , 0 , data , 4 , addr . length ) ; data [ data . length - 2 ] = ( byte ) ( port > > 8 ) ; data [ data . length - 1 ] = ( byte ) ( port ) ; }
construct client request or server response .
