<h2>tkconclient</h2>

<tt>tkconclient</tt> is described in the <a Wiki</a> as means for remote access to another Tcl interpreter using the <a console in socket mode.

For an interactive [AndroWish] this can be achieved by adding these lines to (the Tcl script getting sourced when an interactive <tt>wish</tt> or [AndroWish] is started)

<verbatim>
    package require tkconclient
    tkconclient::start 12345
</verbatim>

meaning that TCP port 12345 is accepting incoming connections from <tt>tkcon</tt> on all interfaces. If the Android device is connected to the development system using an USB cable, it is possible to redirect port 12345 to that USB connection:

<verbatim>
    # on development system, instruct adb (Android Debug Bridge from SDK)
    # to forward TCP port 12345
    adb forward tcp:12345 tcp:12345
</verbatim>

Then <tt>tkcon</tt> can connect in socket mode to <tt>localhost:12345</tt>. Alternatively, the netcat tool <tt>nc</tt> can be used but no input prompts are shown:

<verbatim>
    # netcat on development system, either called "netcat" or "nc"
    nc localhost 12345
</verbatim>

Alternatively, the <tt>socat</tt> tool can be used similar to netcat:

<verbatim>
    # socat on development system
    socat TCP:localhost:12345 STDIO
</verbatim>

Even ye good olde <tt>telnet</tt> should do:

<verbatim>
    # telnet on development system
    telnet localhost 12345
</verbatim>

Similarly, the comm package from tcllib can be used in as

<verbatim>
    package require comm
    comm::comm new comm::comm -port 12347 -local 1 -listen 1 -silent 1
</verbatim>

where the TCP port used is 12347 on the local interface. The adb redirection in this case is:

<verbatim>
    adb forward tcp:12347 tcp:12347
</verbatim>

My own is somewhat larger:

<verbatim>
    # Start socket for tkcon
    #
    # When used over ADB USB debug connection
    # the TCP port 12345 must be forwarded using
    #
    #   adb forward tcp:12345 tcp:12345

    catch {
        package require tkconclient
        tkconclient::start 12345
    }

    # Start socket for comm
    #
    # When used over ADB USB debug connection
    # the TCP port 12347 must be forwarded using
    #
    #   adb forward tcp:12347 tcp:12347

    catch {
        package require comm
        comm::comm new comm::comm -port 12347 -local 1 -listen 1 -silent 1
    }

    # Start dropbear SSH/SFTP daemon using librun.so
    # which is on the path of executable programs and
    # located in the directory where all AndroWish
    # shared libraries are installed.
    #
    # When used over ADB USB debug connection
    # the TCP port 12346 must be forwarded using
    #
    #   adb forward tcp:12346 tcp:12346
    #
    # The public key of the development system
    # must have been copied to
    # of the Android device. $env(HOME) is usually
    #
    # This allows to SSH into the device as the AndroWish user
    # or to SFTP to/from the device as the AndroWish user.
    # That poor AndroWish user is the uid under which the Android
    # package manager decided to install the AndroWish APK.

    catch {
        exec librun.so libdropbear.so dropbear_main -R -p 12346
    }

    # Other goodies accessible through librun.so
    #
    # tclsh:        librun.so libtcl.so tclsh ...
    # sqlite3:      librun.so libtclsqlite3.so sqlite3_shell ...
    # ssh:          librun.so libdropbear.so cli_main ...
    # scp:          librun.so libdropbear.so scp_main ...
    # dropbearkey:  librun.so libdropbear.so dropbearkey_main ...
    # curl:         librun.so libcurl.so curl_main ...
</verbatim>