[ Table Of Contents | Keyword Index ]

ns_sockcallback(n) 4.99 "NaviServer Built-in Commands"

NAME

ns_sockcallback - Register a socket callback script

TABLE OF CONTENTS

    TABLE OF CONTENTS
    SYNOPSIS
    DESCRIPTION
    COMMANDS
    EXAMPLES
    SEE ALSO
    KEYWORDS

SYNOPSIS

ns_sockcallback sockid script when

DESCRIPTION

ns_sockcallback registers a socket callback script. The script should accept the arguments sockid and when. The script will be called according to the value of the when argument as follows: Value of, when Condition under which the script will be called:

COMMANDS

ns_sockcallback sockid script when

EXAMPLES

 
set sock [ns_socklisten * 9000]
ns_sockcallback $sock newconn r

# Keep $sock from closing after connection ends
detach $sock

# When a connection arrives, newconn will be called as:
# newconn $sock r
proc newconn {sock when} {
  set fds [ns_sockaccept $sock]
  set rfd [lindex $fds 0]
  set wfd [lindex $fds 1]
  puts $wfd "Hello!"
  close $rfd
  close $wfd
}

SEE ALSO

nsd

KEYWORDS

NaviServer