#Set up a server socket on port 14000, with a callback to the socketAccept procedure:
set s [socket -server socketAccept 14000]
#This proc gets the socket connection from any client connection. It will be called with the open handle identifier, the address of the client, and the connecting port. The only one we really care about for communications purposes is the sock argumane.
proc socketAccept {sock addr port} {
gets $sock buffer
puts $sock "Thanks for $buffer"
#Flush so the client sees it right away.
flush $sock
#If we are done, then close the socket...
close $sock
}
Run the above, then telnet into the machione at 14000:
telnet localhost 14000
$hello
Thanks for hello
Connection closed by foreign host
Play. Enjoy. If you are not having fun, then you are not doing it right.
Mike Suttles
Xerox OPBU Technology Development Group
Writing for windows...
I have the basic format I want already, but I wanted to see something a little more extended: say for instance a
socket app that had functionality for an interactive query of the filesystem:
proc f_list { dir } {
for {set i 0} {$i < 100} {incr i} {
foreach d [glob $f_dir ] {
if {[file isdirectory $d]} {
set newdirs(r_curse,$i) $d
foreach n_d [array names newdirs] {
...
} else {
file stat $d filer
}
etc..
Short: Build a recursive search for various file info
and allow this information to be queried by a remote user.
I have already written a basic server for this, based on
an echo server example..My server proc is very similar to yours, except that it does some error checking and serves
an interface for the user to query the filesystem..
The server proc works fine-retrieving the info is a pain.
There are many problems with it so I was hoping to find an example similar to what I want to do and learn from it...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.