Re: TCL socket connection
- From: Wolf Grossi <ng-wg@xxxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 20:43:13 +0200
JudgeDread wrote:
Hello Gurus
I have a problem using the tcl socket command. I am using the following code to establish a socket connection from a client to a server. The problem is that i seem to be able to get it only to echo once. How do i establish a socket connection that stays up and does not cause the client to hang when I issue another echo request to the server?
much appreciated
Server
The echo service. 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 2540
vwait forever
Client proc Echo_Client {host port} { set s [socket $host $port] fconfigure $s -buffering line return $s } set s [Echo_Client localhost 2540] puts $s "Hello!" gets $s
Try a flush after every puts. HtH Wolf .
- References:
- TCL socket connection
- From: JudgeDread
- TCL socket connection
- Prev by Date: Re: Having problem with SPLIT
- Next by Date: Re: Having problem with SPLIT
- Previous by thread: TCL socket connection
- Index(es):
Relevant Pages
|