@TK_STARTUP@

# rhello.tk
#
# This agent jumps to a remote machine and displays the "Hello, World!"
# window on that machine.  It gets the name of the remote machine from the
# user.

proc hello {} {

  global agent

    # create the main window 

  main create -name Hello -display $agent(actual-server):0

    # make the "Hello, World!" button

  button .button -text "Hello, World!" -command {set done 1}
  pack .button

    # wait for the user to interact with the "Hello, World!" button

  tkwait variable done
}

  # turn on authentication since the agent can write to the screen only if
  # the server can authenticate the agent's owner (and is configured so that
  # this owner can access the screen) 

set code [
    catch {
       security signatures on
    } result
]

if {$code} {
    puts "Unable to turn on digital signatures:"
    puts ""
    puts $result
    puts ""
    puts "Proceeding anyways ..."
    puts ""
}

  # ask the user for a machine

puts "Enter the name of the remote machine:"
gets stdin machine

  # register the agent

agent_begin

  # submit the agent that will create the window

agent_submit $machine -procs hello -script hello

  # wait for the response from the child agent

set source [agent_receive code string -blocking]

if {$code == "0"} {
    puts "Done!"
} else {
    puts "Error in child (while on machine [lindex $source 0]):"
    puts [lindex $string 2]
}

  # we're done

agent_end
exit
