NaviServer - programmable web server
4.99  5.0

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_sockopen(n) 5.0.0a naviserver "NaviServer Built-in Commands"

Name

ns_sockopen - Connect to a remote host on the specified port

Table Of Contents

Synopsis

Description

ns_sockopen uses socket(), bind(), and connect() calls to connect to the remote host (host) on the specified port (port). ns_sockopen returns a list of two file ids: the first one for reads and the second one for writes.

The -nonblock option specifies that the command will return immediately, while the connect is still in progress by the operating system. If you use -nonblock, you then can call ns_sockcheck with the write file id to see if the connect was actually completed.

The -timeout t option specifies how long to wait for the connect to be made. The value t can be specified in the form secs?:microsecs?, or secs.fraction, or as a number with a time unit.

COMMANDS

ns_sockopen ?-nonblock? ?-timeout? host port

EXAMPLES

 set fds [ns_sockopen www.aolserver.com 80]
 set rid [lindex $fds 0]
 set wid [lindex $fds 1]
 puts $wid "GET /index.htm HTTP/1.0\r\n\r"
 flush $wid
 while {[set line [string trim [gets $rid]]] != ""} {
  lappend headers $line
 }
 set page [read $rid]
 close $rid
 close $wid

See Also

ns_sockcallback, ns_sockcheck, ns_time

Keywords

NaviServer, global built-in, socket