public void requestX11Forwarding(String hostname,int port,byte[] cookie,boolean singleConnection) throws IOException {
  if (hostname == null)   throw new IllegalArgumentException("hostname argument may not be null");
synchronized (this) {
    if (flag_closed)     throw new IOException("This session is closed.");
    if (flag_x11_requested)     throw new IOException("X11 forwarding was already requested.");
    if (flag_execution_started)     throw new IOException("Cannot request X11 forwarding at this stage anymore, a remote execution has already started.");
    flag_x11_requested=true;
  }
  X11ServerData x11data=new X11ServerData();
  x11data.hostname=hostname;
  x11data.port=port;
  x11data.x11_magic_cookie=cookie;
  byte[] fakeCookie=new byte[16];
  String hexEncodedFakeCookie;
  while (true) {
    rnd.nextBytes(fakeCookie);
    StringBuffer tmp=new StringBuffer(32);
    for (int i=0; i < fakeCookie.length; i++) {
      String digit2=Integer.toHexString(fakeCookie[i] & 0xff);
      tmp.append((digit2.length() == 2) ? digit2 : "0" + digit2);
    }
    hexEncodedFakeCookie=tmp.toString();
    if (cm.checkX11Cookie(hexEncodedFakeCookie) == null)     break;
  }
  cm.requestX11(cn,singleConnection,"MIT-MAGIC-COOKIE-1",hexEncodedFakeCookie,0);
synchronized (this) {
    if (flag_closed == false) {
      this.x11FakeCookie=hexEncodedFakeCookie;
      cm.registerX11Cookie(hexEncodedFakeCookie,x11data);
    }
  }
}

public void requestX11Forwarding ( String hostname , int port , byte [ ] cookie , boolean singleConnection ) throws IOException { if ( hostname == null ) throw new IllegalArgumentException ( "hostname argument may not be null" ) ; synchronized ( this ) { if ( flag_closed ) throw new IOException ( "This session is closed." ) ; if ( flag_x11_requested ) throw new IOException ( "X11 forwarding was already requested." ) ; if ( flag_execution_started ) throw new IOException ( "Cannot request X11 forwarding at this stage anymore, a remote execution has already started." ) ; flag_x11_requested = true ; } X11ServerData x11data = new X11ServerData ( ) ; x11data . hostname = hostname ; x11data . port = port ; x11data . x11_magic_cookie = cookie ; byte [ ] fakeCookie = new byte [ 16 ] ; String hexEncodedFakeCookie ; while ( true ) { rnd . nextBytes ( fakeCookie ) ; StringBuffer tmp = new StringBuffer ( 32 ) ; for ( int i = 0 ; i < fakeCookie . length ; i ++ ) { String digit2 = Integer . toHexString ( fakeCookie [ i ] & 0xff ) ; tmp . append ( ( digit2 . length ( ) == 2 ) ? digit2 : "0" + digit2 ) ; } hexEncodedFakeCookie = tmp . toString ( ) ; if ( cm . checkX11Cookie ( hexEncodedFakeCookie ) == null ) break ; } cm . requestX11 ( cn , singleConnection , "MIT-MAGIC-COOKIE-1" , hexEncodedFakeCookie , 0 ) ; synchronized ( this ) { if ( flag_closed == false ) { this . x11FakeCookie = hexEncodedFakeCookie ; cm . registerX11Cookie ( hexEncodedFakeCookie , x11data ) ; } } }
request x11 forwarding for the current session . < p > you have to supply the name and port of your x - server . < p > this method may only be called before a program or shell is started in this session .
