Doing the echo service example in the book, 'Practical Programming in Tcl & TK 4th edition' Brent B. Welch Ken Jones Jeffrey Hobbs.
Its on page 241, example 17-3. Copied it straight out of the book and its giving me the following error:
tclsh "theEchoService.tcl" (in directory: /home/<username>/Documents/Scripts/tcl)
Compilation failed.
wrong # args: should be "proc name args body"
while executing
"proc Echo {sock} \
{
global echo
if {[eof $sock]} || [catch {gets $sock line}]} \
{
;# end of file or abnormal connection drop
close $sock
pu..."
(file "theEchoService.tcl" line 16)
Heres my full code:
#!/usr/bin/tclsh
;#The Echo Service. Socket ProgrammingPage 241, Example 17-3
proc Echo_Server {port} \
{
global echo
set echo(main) [socket -server EchoAccept $port]
}
proc EchoAccept {sock addr port} \
{
global echo
puts "Accept $sock from $addr $port"
set echo(addr, $sock) [list $addr $port]
fconfigure $sock -buffering line
fileevent $sock readable [list Echo $sock]
}
proc Echo {sock} \
{
global echo
if {[eof $sock]} || [catch {gets $sock line}]} \
{
;# end of file or abnormal connection drop
close $sock
puts "Close $echo(addr, $sock)"
unset echo(addr,$sock)
} \
else \
{
if {[string compare $line "quit"] == 0} \
{
;# Prevent new connections, Existing connections stay open
close $echo(main)
}
puts $sock $line
}
}
I've tried it without my escapes and still the same. Any ideas?