Subject: Announce new 0.2 release of EasySocket package makes using async sockets a snap. - DN [1]


Mo <mo@nospam.com> - 16 Dec 1999 - comp.lang.tcl

 One of the most common postings to the comp.lang.tcl newsgroup
 are requests for examples and information about how to use the
 socket command. I am providing the EasySocket package to address
 this need. This package is an OO style class that provides async
 socket functionality without requiring that the user know all
 the details of the socket and fileevent commands. Programmers
 can examine the source code of the EasySocket package to see
 some good examples of async sockets in action, or they can
 simply use the package to do async socket communication in
 their own apps. This package is pure Tcl code, just download
 the code and unzip or untar the archive in the lib directory
 where Tcl is installed. This new 0.2 release includes bug fixes
 and some new code to deal with common socket error conditions
 like EPIPEs and network timeouts.

 http://www.cs.umn.edu/~dejong/tcl/EasySocket.tar.gz
 http://www.cs.umn.edu/~dejong/tcl/EasySocket.zip

 Here is a quick example that shows how to use the package.
 This example creates a socket connection to the netscape web
 server and downloads the homepage a line at a time. Your app
 must enter the event loop for socket events to be processed.
 The most simple way to do that is to run these commands in wish.

 package require EasySocket

 Socket s -ready MsgReady

 proc MsgReady { msg } {
   puts "got msg \"$msg\" from server"
 }

 s connect www.netscape.com 80
 s send "GET /\n"

 Here is a more complex example that uses the FTP
 protocol to find out the size of a file on
 the Scriptics FTP server. Run these commands line
 by line inside wish to see the results.

 package require EasySocket

 Socket s -ready MsgReady

 proc MsgReady { msg } {
   puts "got msg \"$msg\" from server"

   # Check for size msg from the ftp server
   if {[lindex $msg 0] == 213} {
     global size
     set size [lindex $msg 1]
   }
 }

 s connect ftp.scriptics.com 21
 s send "USER anonymous"
 s send "PASS no@addr.com"
 s send "CWD pub/tcl/java"
 s send "SIZE jaclSrc125.zip"

 s disconnect

 puts "file size is $size bytes"

 Mo DeJong
 Cygnus Solutions

Last modified
2000-01-04

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated