tkconclient
Not logged in

tkconclient

tkconclient is described in the Tcl Wiki as means for remote access to another Tcl interpreter using the tkcon console in socket mode.

For an interactive AndroWish this can be achieved by adding these lines to ~/.wishrc (the Tcl script getting sourced when an interactive wish or AndroWish is started)

    package require tkconclient
    tkconclient::start 12345

meaning that TCP port 12345 is accepting incoming connections from tkcon 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:

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

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

    # netcat on development system, either called "netcat" or "nc"
    nc localhost 12345

Alternatively, the socat tool can be used similar to netcat:

    # socat on development system
    socat TCP:localhost:12345 STDIO

Even ye good olde telnet should do:

    # telnet on development system
    telnet localhost 12345

Similarly, the comm package from tcllib can be used in ~/.wishrc as

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

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

    adb forward tcp:12347 tcp:12347

My own ~/.wishrc is somewhat larger:

    # 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 $env(HOME)/.ssh/authorized_keys
    # of the Android device. $env(HOME) is usually /data/data/tk.tcl.wish/files
    #
    # 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 ...