Version 0 of Tcl Tutorial Lesson 26a

Updated 2017-06-19 14:24:56 by arjen

Communicating with other programs - socket, fileevent

TODO: lesson on socket and fileevent (or "chan event" in 8.5). But see also Lesson 40: socket, fileevent, vwait


Example

#
# A little echo server
#
proc accept {socket address port} {
    puts "Accepted connection $socket from $address\:$port"

    # Copy input from the socket directly back to the socket

    chan copy $socket $socket -command [list finish $socket]
}
proc finish {socket args} {
    puts "Closed $socket"
    catch { chan close $socket }
}
socket -server accept 8080
# Start the event loop by waiting on a non-existant variable 'forever'
vwait forever