Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Echo-server/Tcl/echo-server-1.tcl
Normal file
21
Task/Echo-server/Tcl/echo-server-1.tcl
Normal 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
|
||||
16
Task/Echo-server/Tcl/echo-server-2.tcl
Normal file
16
Task/Echo-server/Tcl/echo-server-2.tcl
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue