TCL socket connection



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
 
 


Relevant Pages

  • Re: TCP receive too many small packets
    ... I have a client / server application that communicates with each other ... thru a socket connection. ... Is something wrong with sending small TCP packets? ...
    (microsoft.public.win32.programmer.networks)
  • Pass an open SOCKET to a new process?
    ... I've got a WinSock server process which accepts a socket connection and then ... I need to somehow pass the client connection on "sock" on to the new process ... This is a port of a server from UNIX land. ...
    (microsoft.public.win32.programmer.networks)
  • Re: TCP receive too many small packets
    ... I have a client / server application that communicates with each other ... thru a socket connection. ... Is something wrong with sending small TCP packets? ...
    (microsoft.public.win32.programmer.networks)
  • Re: TCL socket connection
    ... 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? ...
    (comp.lang.tcl)
  • OpenVPN error "MULTI: bad source address ..." and routing issue
    ... I'm trying to connect a WinXP client to an OpenVPN 2.0.9 server ... Another problem I have is that after the connection is established the ... 10.7.15.5: icmp: echo request ...
    (comp.unix.bsd.openbsd.misc)