Communicating with other programs - socket, fileevent

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
    fcopy $socket $socket -command [list finish $socket]
}
proc finish {socket args} {
    puts "Closed $socket"
    catch { close $socket }
}
socket -server accept 8080
# Start the event loop by waiting on a non-existant variable 'forever'
vwait forever