public static void removeForward(InetSocketAddress adbSockAddr,Device device,String localPortSpec,String remotePortSpec) throws TimeoutException, AdbCommandRejectedException, IOException {
  try (SocketChannel adbChan=SocketChannel.open(adbSockAddr)){
    adbChan.configureBlocking(false);
    byte[] request=formAdbRequest(String.format("host-serial:%1$s:killforward:%2$s",device.getSerialNumber(),localPortSpec));
    write(adbChan,request);
    AdbResponse resp=readAdbResponse(adbChan,false);
    if (!resp.okay) {
      Log.w("remove-forward","Error creating forward: " + resp.message);
      throw new AdbCommandRejectedException(resp.message);
    }
  }
 }

public static void removeForward ( InetSocketAddress adbSockAddr , Device device , String localPortSpec , String remotePortSpec ) throws TimeoutException , AdbCommandRejectedException , IOException { try ( SocketChannel adbChan = SocketChannel . open ( adbSockAddr ) ) { adbChan . configureBlocking ( false ) ; byte [ ] request = formAdbRequest ( String . format ( "host-serial:%1$s:killforward:%2$s" , device . getSerialNumber ( ) , localPortSpec ) ) ; write ( adbChan , request ) ; AdbResponse resp = readAdbResponse ( adbChan , false ) ; if ( ! resp . okay ) { Log . w ( "remove-forward" , "Error creating forward: " + resp . message ) ; throw new AdbCommandRejectedException ( resp . message ) ; } } }
remove a port forwarding between a local and a remote port .
