Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,21 @@
# How to handle an incoming new connection
proc acceptEcho {chan host port} {
puts "opened connection from $host:$port"
fconfigure $chan -blocking 0 -buffering line -translation crlf
fileevent $chan readable [list echo $chan $host $port]
}
# How to handle an incoming message on a connection
proc echo {chan host port} {
if {[gets $chan line] >= 0} {
puts $chan $line
} elseif {[eof $chan]} {
close $chan
puts "closed connection from $host:$port"
}
# Other conditions causing a short read need no action
}
# Make the server socket and wait for connections
socket -server acceptEcho -myaddr localhost 12321
vwait forever

View file

@ -0,0 +1,16 @@
# How to handle an incoming new connection
proc acceptEcho {chan host port} {
puts "opened connection from $host:$port"
fconfigure $chan -translation binary -buffering none
fcopy $chan $chan -command [list done $chan $host $port]
}
# Called to finalize the connection
proc done {chan host port args} {
puts "closed connection from $host:$port"
close $chan
}
# Make the server socket and wait for connections
socket -server acceptEcho -myaddr localhost 12321
vwait forever