Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 94eb52100855dbfade0659dbe4316acce8374d26
Ticket: 218467ffffffffffffffffffffffffffffffffff
Server Socket Errors
User & Date: nobody on 2000-10-26 01:00:49
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed 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 changed to: "obsolete: 8.0"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "63. (unused)"
  10. title changed to: "Server Socket Errors"
  11. type changed to: "Bug"