Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tcl socket examples

Status
Not open for further replies.

marsd

IS-IT--Management
Apr 25, 2001
2,218
US
i need some examples of server -socket scripts that
accept input from the remote user, any ideas where
one can find some of these?
 
Here's the basic script for server side stuff:

#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
 
Thanks charlsut..

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...

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top