summaryrefslogtreecommitdiffstats
path: root/doc/socket.n
diff options
context:
space:
mode:
Diffstat (limited to 'doc/socket.n')
-rw-r--r--doc/socket.n20
1 files changed, 13 insertions, 7 deletions
diff --git a/doc/socket.n b/doc/socket.n
index 6fe5517..7596abb 100644
--- a/doc/socket.n
+++ b/doc/socket.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: socket.n,v 1.19 2010/01/20 13:42:17 dkf Exp $
+'\" RCS: @(#) $Id: socket.n,v 1.20 2010/02/24 10:11:46 dkf Exp $
.so man.macros
.TH socket n 8.0 Tcl "Tcl Built-In Commands"
.BS
@@ -100,6 +100,7 @@ using \fBfconfigure\fR to read the \fB\-sockname\fR option).
Tcl will automatically accept connections to the given port.
For each connection Tcl will create a new channel that may be used to
communicate with the client. Tcl then invokes \fIcommand\fR
+(properly a command prefix list, see the \fBEXAMPLES\fR below)
with three additional arguments: the name of the new channel, the
address, in network address notation, of the client's host, and
the client's port number.
@@ -164,24 +165,29 @@ list is identical to the address, its first element.
Here is a very simple time server:
.PP
.CS
-proc Server {channel clientaddr clientport} {
+proc Server {startTime channel clientaddr clientport} {
puts "Connection from $clientaddr registered"
- puts $channel [clock format [clock seconds]]
+ set now [clock seconds]
+ puts $channel [clock format $now]
+ puts $channel "[expr {$now - $startTime}] since start"
close $channel
}
-\fBsocket\fR -server Server 9900
+\fBsocket -server\fR [list Server [clock seconds]] 9900
vwait forever
.CE
.PP
-And here is the corresponding client to talk to the server:
+And here is the corresponding client to talk to the server and extract
+some information:
.PP
.CS
set server localhost
set sockChan [\fBsocket\fR $server 9900]
-gets $sockChan line
+gets $sockChan line1
+gets $sockChan line2
close $sockChan
-puts "The time on $server is $line"
+puts "The time on $server is $line1"
+puts "That is [lindex $line2 0]s since the server started"
.CE
.SH "SEE ALSO"
fconfigure(n), flush(n), open(n), read(n)