Tcl 8.5 Network Programming

Book description

Learn Tcl and you’ll never look back when it comes to developing network-aware applications. This book is the perfect way in, taking you from the basics to more advanced topics in easy, logical steps.

  • Develop network-aware applications with Tcl

  • Implement the most important network protocols in Tcl

  • Packed with hands-on-examples, case studies, and clear explanations for better understanding

  • In Detail

    Tcl (Tool Command Language) is a very powerful and easy to learn dynamic programming language, suitable for a very wide range of uses. Tcl is regarded as one of the best-kept secrets in the software industry. This book gives you a hands-on experience on Tcl, helping you develop network-aware applications using this mature yet evolving language.

    This book shows you how to create network-aware applications with Tcl language. Packed with practical examples, the book not only takes you through the implementation of network protocols in Tcl, but also key aspects of Tcl programming.

    The book starts with the basic element of Tcl programming as we take a look at the syntax and fundamental commands of the language. To get us ready for network programming, we look at important Tcl features such as object-oriented programming, accessing files, packaging in TCL, event driven programming, and multithreaded applications. To create standalone single-file executable applications with Tcl we take a look at the Starpack technology, and ensure that we’ll be able to create robust applications with a thorough coverage of troubleshooting and debugging Tcl applications.

    The book is really about network programming, and it will not let you down with its deep coverage of these topics. Of course we look at protocols, but there are plenty of practical examples to keep things moving along. We start with the TCP and UDP protocols, and look at some other protocols to see examples of synchronizing time with other servers, querying user information and authenticating users over LDAP and performing DNS queries.

    The book explains Simple Network Management Protocol (SNMP), which is often used for monitoring and gathering information from various devices, such as routers, gateways, printers and many other types of equipment. We’ll also look at web programming in Tcl; processing the requests coming from the clients via the HTTP protocol and responding to these requests. You’ll be able to create a complete solution for creating a client-server application in Tcl.

    To round things off, you’ll see how to secure your networked applications, build public key infrastructure into your application and use Tcl’s safe interpreter feature to reduce risk of running code from unknown source.

    This book will be help you discover a range of network protocols and concepts and show how to implement them in Tcl

    Table of contents

    1. Tcl 8.5 Network Programming
      1. Tcl 8.5 Network Programming
      2. Credits
      3. About the Authors
      4. About the Reviewers
      5. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      6. 1. Introducing Tcl
        1. What is Tcl/Tk
          1. Extensions
          2. Tk
        2. Installation
          1. Windows
          2. Unix-like systems
          3. Installation of additional Tcl packages
        3. Additional tools
          1. Eclipse
          2. Komodo
          3. tkcon — an alternate Tcl shell
        4. Tcl syntax
          1. Tcl commands documentation syntax
          2. Running the script
          3. Running commands directly in the tclsh interpreter
          4. Variables
          5. Grouping
          6. Nesting commands
          7. Data types
            1. Lists
            2. Arrays
              1. array size
            3. Dictionaries
            4. Mathematical expressions—expr
            5. Flow control and loop instructions
              1. Flow control
              2. Loops
            6. Defining your own commands
        5. Summary
      7. 2. Advanced Tcl Features
        1. Tcl features
          1. Working with time and date
          2. Tcl data types
          3. Global, namespace, and local variables
          4. Stack frames
        2. Object-oriented programming
          1. Class definition
          2. Inheritance
          3. Object definitions
          4. Using mixins
          5. Forwarding methods
          6. Additional information
        3. Accessing files
          1. Reading and writing files
          2. Configuring channel options
          3. File management
          4. Filename related operations
          5. File information
          6. Listing files
          7. Current working directory
        4. Packages in Tcl
          1. Package loading
          2. Creating a package
          3. Tcl modules
        5. Event-driven programming
          1. Tcl event types
          2. Entering the event loop
          3. Events and stack frames
          4. Channel events
          5. Timer and idle events
          6. Robust scheduling with tclcron
        6. Multithreaded applications
          1. Managing threads
          2. Shared variables
          3. Transferring channels
        7. Summary
      8. 3. Tcl Standalone Binaries
        1. Understanding the executable file structure
        2. Learning the Metakit database
          1. Working with MetaKit from Tcl
        3. Learning more about virtual file systems
          1. Getting into the details of VFS and Metakit
        4. Learning Tclkit
        5. Starkit and SDX
          1. Creating a Starkit file
          2. Internal structure of starkits
            1. Using resource files in starkits
            2. Putting additional packages into a starkit
          3. Format of the starkit file
          4. Interactions between different starkit files
        6. Knowing the Starpack technology
        7. Practical example—the Hibernator application
        8. Advanced topics—self updating
        9. Other solutions
        10. Summary
      9. 4. Troubleshooting Tcl applications
        1. Logging
          1. Log package
            1. Initialization
            2. Available log levels
            3. Enabling or disabling log levels
            4. Replacing the default implementation of the logging command
            5. Recap of the log package
          2. Logger package
            1. Initialization
            2. Available log levels
            3. Enabling or disabling log levels
            4. Tracing
            5. Changing the implementation of the logging / tracing command
            6. Appenders
            7. Recap of the logger package
          3. Audit
            1. Recap of the audit package
        2. Debugging
          1. Tcl Dev Kit Inspector
          2. Tcl Dev Kit Debugger
            1. Local Debugging
            2. Remote debugging
            3. Recap of the Tcl Dev Kit Debugger
          3. TclPro Debugger
        3. Summary
      10. 5. Data Storage
        1. Internationalizations
          1. Encoding issues
          2. Translating your application into different languages
        2. Using SQL and databases in Tcl
          1. Connecting to MySQL
          2. Connecting to PostgreSQL
          3. Using SQLite
            1. Managing databases from SQLiteStudio
          4. Other databases
        3. Handling XML in Tcl
        4. Storing raw Tcl values
        5. Summary
      11. 6. Networking in Tcl
        1. Using TCP sockets
          1. Creating server sockets
          2. Connecting over TCP
          3. Using nonblocking sockets
            1. Handling channel events
          4. Transferring binary data
            1. Transferring data using the fcopy command
          5. Handling errors
          6. Buffering
          7. Using threads for networking
            1. Using threads and thread pools
            2. Connecting to our service
        2. Using UDP sockets
          1. Creating a UDP-based client
          2. Implementing service using UDP
          3. Sending reliable messages
          4. Comparing TCP and UDP: streams vs. datagrams
        3. Summary
      12. 7. Using Common Internet Services
        1. Handling e-mail
          1. Learning MIME
            1. Content type
            2. Multipart messages
          2. MIME in Tcl
            1. Creating messages
            2. Multipart elements
          3. Sending e-mails
            1. Automated e-mail sending
            2. Creating template based e-mails
          4. Receiving e-mails
            1. Using POP3 protocol in Tcl
            2. Listing all messages
            3. Retrieving e-mails using POP3
            4. Parsing incoming e-mails
        2. Transferring files and data
          1. Resources and uri package
          2. Using HTTP
            1. Retrieving data over HTTP
            2. Submitting information using GET and POST
            3. Advanced topics
            4. Cookies in Tcl
            5. HTTP and encryption
            6. Retrieving RSS information
          3. Using FTP
            1. Establishing connections
            2. Retrieving files
            3. Uploading files
            4. Listing files and directories
        3. Summary
      13. 8. Using Additional Internet Services
        1. Checking DNS
          1. Using callbacks
        2. Getting the current date and time
        3. Using LDAP from Tcl
          1. Authenticating users over LDAP
          2. Modifying information in LDAP
        4. Communicating with Tcl applications
          1. Comm client and server
          2. Performing commands asynchronously
          3. Security aspects
          4. Limiting available commands
        5. Summary
      14. 9. Learning SNMP
        1. Introduction to SNMP
          1. Learning SNMP protocol versions
          2. Data objects
          3. Working with SNMP and MIB
          4. Setting up SNMP agent
        2. Tcl and Scotty package
          1. Obtaining Scotty
          2. The TkIned application
        3. Using Tcl for SNMP communication
          1. Querying SNMP in Tcl
          2. Performing asynchronous queries
          3. Walking over MIB trees
          4. Receiving traps
          5. Sending traps
          6. SNMP agent
          7. Additional features
        4. Summary
      15. 10. Web Programming in Tcl
        1. Tcl scripts as CGI application
          1. Using ncgi package
          2. Using html package
        2. Introduction to TclHttpd
          1. Installation
            1. Retrieving source code from the CVS repository
          2. Documentation
          3. First run
            1. Startup parameters
          4. Default directory structure
          5. Configuration
          6. Performance
        3. Programming TclHttpd server
          1. Providing static content
          2. Using CGI in TclHttpd
          3. Mapping URL to application
          4. Creating document type handlers
            1. Using the watermark example
            2. Creating custom templates
          5. Learning domain handlers
              1. Setting up request handlers
            1. Comparing domain handlers to application direct URLs
            2. Creating session-based authentication
          6. Using the TclHttpd template system
          7. Securing access to resources
          8. Debugging TclHttpd server
          9. Embedding TclHttpd in your application
        4. Summary
      16. 11. TclHttpd in Client-Server Applications
        1. Creating HTTP-based applications
          1. Preparing source code structure
          2. Creating our applications
            1. Server-side
            2. Client-side
          3. Communication and registration
            1. Server-side
            2. Client-side
          4. Storing information
            1. Server side
            2. Client side
          5. Comm interface—spooling jobs
          6. Testing our applications
        2. Adding autoupdate to application
          1. Server-side
          2. Client-side
        3. Extending your applications
          1. Starkits as extensions
          2. Building modules
          3. Server side
          4. Handling modules on client
          5. Communication with server
        4. Improving scalability and performance
        5. Summary
      17. 12. SOAP and XML-RPC
        1. Tcl and standards for remote procedure calls
        2. Connecting to XML-RPC services
            1. Defining available methods
            2. Specifying data types
            3. Using XML-RPC
        3. Using SOAP protocol
          1. Creating Web Services
            1. Setting up server
            2. Creating a service
            3. Specifying data types
            4. Creating service methods
            5. Defining data types
              1. Using simple data types
              2. Creating complex data types
            6. Using data types inside service
          2. Connecting to SOAP based services
            1. Invoking methods via commands
            2. Invoking methods API using DoCall commands
            3. Using complex data types
        4. Summary
      18. 13. SSL and Security
        1. Learning Secure Socket Layer
          1. Using SSL from Tcl
          2. Generating self-signed certificates
          3. Setting up and using public key infrastructure
            1. Setting up certificates manually
              1. Creating certificate authority
              2. Generating and signing keys
            2. Automating certificates from Tcl
          4. Managing certificates from Tcl
            1. Server side
            2. Client side
            3. Testing our solution
          5. SSL and performance issues
        2. Authorization and roles
        3. Securing your application
          1. Slave interpreters
            1. Using slave interpreters
            2. Sharing information with the slave interpreter
            3. Creating and managing aliases
            4. Deleting interpreters
            5. Imposing limits on interpreters
          2. Working with safe interpreters
            1. Hiding and exposing commands
            2. Default safe interpreter setup
            3. Using Safe Base
            4. Safe Base and filesystem access
          3. Role-based authorization and interpreters
            1. Creating interpreters using roles
            2. Sample role definitions
            3. Using role-based interpreters
        4. Summary

    Product information

    • Title: Tcl 8.5 Network Programming
    • Author(s):
    • Release date: July 2010
    • Publisher(s): Packt Publishing
    • ISBN: 9781849510967