title: Socket timeout after some time
body: <p>If the server went into a infinite loop, how we can close the server connection after sometime?</p>
  
  <p>Here is the code in which I am trying:</p>
  
  <pre><code>    set s [socket $host $port]
      fconfigure $s -blocking 1 -buffering line
      after 2000 set end 1
      vwait end
      if { $s != "" } {
  
              puts -nonewline $s "$msg\n.\n"
              flush $s
              fileevent $s readable [set answer [read $s]]
  
              puts "$answer"
  
              if {[catch {close $s}]} {
                      puts "Server hanged"
              }
  </code></pre>
  
  <p>This above code is working if the answer was given by the server without any problem. If the server went into infinite loop, it is keep on hanging in <code>read $s</code>. Please help on how to handle this <code>read socket</code> in a non-blocking mode as like in <code>fconfigure</code>.</p>