Hi All,
I have a server socket script that waits and handle request from the client socket. I got this script from the Brent B. Welch TCL/TK book.
I need run the script all the time so that it can wait and listen for the input from client. How can I run this as a background service? Is there any other way to keep it running all the time without any manual intervention?
Thanks for help in advance.
Regards
Mo
Here is the script:
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 $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
}
}
Echo_Server 2500
vwait forever
I have a server socket script that waits and handle request from the client socket. I got this script from the Brent B. Welch TCL/TK book.
I need run the script all the time so that it can wait and listen for the input from client. How can I run this as a background service? Is there any other way to keep it running all the time without any manual intervention?
Thanks for help in advance.
Regards
Mo
Here is the script:
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 $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
}
}
Echo_Server 2500
vwait forever