Skip to content
Tcl Source Code History Of Ticket 218467
Login

History Of Ticket 218467

Artifacts Associated With Ticket 218467

  1. Ticket change [94eb521008] (rid 106079) by nobody on 2000-10-26 01:00:49:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 628 Bug
      Version: 8.0
      SubmitDate: '1998-05-25'
      LastModified: '1999-09-13'
      Severity: LOW
      Status: Released
      Submitter: hershey
      ChangedBy: hobbs
      OS: Windows NT
      OSVersion: 4.0
      Machine: NA
      FixedDate: '1999-09-13'
      FixedInVersion: 8.2
      ClosedDate: '2000-10-25'
      
      
      [email protected]
      
      Hello, I am having a problem dealing with socket errors. I took an 
      example from the Welch book and implemented it on Win NT 4.0 using 
      tclsh80.exe. I start my TCL program, and then I connect to it using 
      telnet. I type "Hi" and Enter which it echoes back as designed, but when 
      I use the telnet program to forcefully close the socket, I get the 
      following error from tchsh80.exe:
      
      Reading socket <--- last line of text from my program
      bgerror failed to handle background error.
          Original error: error writing "sock440": connection reset by peer
          Error in bgerror: invalid command name "bgerror"
      
      It looks like my catch and eof logic is not detecting that the socket has 
      closed. Can someone show me how to reliably trap for these errors?
      
      Thanx much, code follows.
      
      ************* Code Below ************
      proc Echo_Server {port} {
              global echo
              set echo [socket -server EchoAccept $port]
      }
      
      proc EchoAccept {sock addr port} {
              puts "Accept $sock from $addr port $port"
              fconfigure $sock -buffering line
              fileevent $sock readable [list Echo $sock]
      }
      
      proc Echo {sock} {
              global echo
              global forever
              puts "Reading socket"
              if {[eof $sock] || [catch {gets $sock line}]} {
              # end of file or abnormal connection drop
              puts "Abnormal socket end"
              close $sock
              } else {
                      if {[string compare $line "quit"] == 0} {
                              puts "Received close command"
                              close $sock
                              # close main socket so no more incoming
                              close $echo
                              set forever 1
                      } else {
                              if {[string compare $line "bye"] == 0} {
                                      puts "Received bye command"
                                      # close main socket so no more incoming
                                      close $sock
                              } else {
                                      puts $sock $line
                                      puts "READ: $line"
                              }
                      }
              }
      }
      
      set forever 0
      Echo_Server 2546
      vwait forever
      Puts "exiting program"
      
      Try instead with the eof code:
      
          if {[eof $sock] || ([gets $sock line] == -1)} {
      SocketShutdown $sock
      return
          }
      
      And better yet, upgrade to 8.2 which has improved socket support
      on Windows. 
      -- 09/13/1999 hobbs
      
    4. foundin initialized to: "obsolete: 8.0"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "63. (unused)"
    10. title initialized to: "Server Socket Errors"
    11. type initialized to: "Bug"
  2. Ticket change [98030fc811] (rid 110538) by welch on 2000-10-26 08:22:17:

    1. closedate changed to: "2000-10-26T01:22:17"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  3. Ticket change [47464fff7b] (rid 99670) by dgp on 2001-04-01 01:47:51:

    1. closedate changed to: "2001-03-31T18:47:51"
    2. closer changed to: "dgp"
    3. subsystem changed to: "27. Channel Types"