Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Tcl 8.5 Network Programming
Tcl 8.5 Network Programming

Tcl 8.5 Network Programming: 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.

eBook
S$53.98 S$59.99
Paperback
S$74.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Tcl 8.5 Network Programming

Chapter 2. Advanced Tcl Features

Now that we know Tcl basics a lot better, it is time to learn some of Tcl's more advanced functionality. This chapter focuses on some aspects of Tcl that will be needed for the chapters that follow throughout the book.

This chapter talks about how Tcl works internally, what we need to be aware of and how we can leverage it to our needs. It introduces in detail how Tcl evaluates code, substitutes variables, and evaluates embedded commands. It also talks about the different types of variables and how they can be used within our code.

We also describe how to work with files in Tcl. This chapter covers how to read and write files, and introduces the concept of channels within Tcl and how different types of channels work. We also show how to copy, rename, and delete files and directories, get information about them, and how to learn about platform-specific issues.

After that, you will see how the Tcl packaging system works and how we can extend it and create reusable...

Tcl features


The previous chapter introduced the basics of the Tcl language. We learned the basics of strings, lists, dictionaries, and integer and floating-point numbers. This section introduces some of the more advanced Tcl features— working with the time and date, data, namespaces, and stack frames.

Learning some of these features is required if you wish to understand and use Tcl and its features in a better way—especially meta programming, which can be used to create our own syntax and alter a program's flow control. This is one of Tcl's powerful features.

Working with time and date

When writing applications in Tcl, we'll often need to work in the context of date and time. One example is reading a file's access time, another one calculating how much time is left until, for example, next Sunday at 4 AM. Tcl uses the Unix timestamp for all date and time manipulations. This is a common approach which assumes that all dates and times are specified as a number of seconds since midnight on the...

Object-oriented programming


Object-oriented programming has been a feature Tcl offered for several years with additional packages. This was possible due to the fact that Tcl syntax is easily extendable. Those packages include Incr Tcl, which is available from http://incrtcl.sourceforge.net/itcl/, XOTcl available from http://media.wu-wien.ac.at/ and Snit which can be obtained from http://www.wjduquette.com/snit/.

However, with the release of version 8.5, Tcl now comes with an object-oriented programming functionality included called TclOO. When Tcl 8.6 is out, TclOO will soon be part of core language. In Tcl 8.5 it is an extension to the language, but leverages 8.5 extensions to support it.

This is a set of additions that allows us to build a class hierarchy on its own. TclOO is designed so that it is possible to build wrappers so that it works the same as Incr Tcl, XOTcl, or Snit. So, for those of you that use any OO extension, it might be the right time to switch. For those of you that...

Accessing files


Tcl allows us to read from and write to files by using channels. A channel can be an open file, but it can also be a network socket, a pipe, or any other channel type. Depending on the type of the channel, it can support reading from it, writing to it, or both.

Tcl comes with three default channels—stdin, stdout, and stderr. These channels correspond to the standard input, standard output, and standard error channels of operating systems. Standard input can be used to read information from the user, standard output should be used to write information to user, and standard error is used to write errors. Depending on how our application is run, these channels can be redirected from/to files.

In the case of Microsoft Windows and applications using the GUI version of Tcl, invoked using the wish or tclkit commands, standard channels are not available. This is because graphical applications in Microsoft Windows do not have standard consoles. In such cases, an equivalent of these...

Packages in Tcl


Tcl offers a mechanism to look for and create packages—reusable pieces of code, either bundled with Tcl, created as additional projects or code you write and want to use in multiple applications. Packages are meant to provide an easy to use mechanism for using additional libraries—either your library or third-party libraries. Packages are identified using a package name and version.

Package name can be any string, but a good practice is to name the package using lowercase only and using the same name as the namespace used. For example, functionality to work with base64 encoded data is called base64 and all commands are in the base64 namespace.

Versions are one or more numbers separated by dots, where the first leftmost one indicates major versions, and remaining ones indicate additional versioning, with the leftmost being most significant, and the rightmost least significant. Tcl compares versions by separating the numbers using dots and comparing each part as numbers. version...

Event-driven programming


Tcl is designed to use an event-driven model. This means that everything that should happen is either scheduled for a particular time or when an event occurs, such as data being read, a new connection is made, or an external application or database sends a notification. This means that your files, networking, and timers work in the same thread and use events to perform actions when something occurs. For example, in an application with user interface, an action can be bound to user clicking on a button, which causes specific code to be run whenever the user clicks on the button. Similarly, a network server will set up a listening connection and run specific code when a new connection is established. Similarly, whenever application can read or write to a network connection, the particular code can be run.

It is common to develop an application that is event driven. This means that in most cases the application will only do things when an event takes place or will perform...

Multithreaded applications


Even though Tcl is designed to work efficiently in a single-threaded environment, it is possible to create separate threads in Tcl. While it can be used for performing any action, it is usually used for operations that take a lot of time to complete.

Threads in Tcl require that Tcl is built with threading enabled and has the package Thread installed, which is true for all ActiveTcl installations. Tcl builds from various operating system distributions may or may not be built with thread support enabled—in this case, the Thread package may not be present.

Managing threads

Tcl uses that approach that each thread is a separate entity and data is not normally shared across threads. It is possible to send commands to be evaluated in a thread, either waiting for them to finish or by having them performed asynchronously. In order to create a thread, we need to first load the Thread package and use the thread::create command:

package require Thread
set tid [thread::create...

Summary


In this chapter, we learned about some of Tcl features that are needed in order to progress to more advanced topics covered from next chapter on.

We've presented how Tcl handles dates and times, which is very similar to other programming languages. However, the ability to parse human readable date, time, and scheduling definitions is something specific to Tcl and is considered to be a very powerful feature.

We also talked about the internals of Tcl, and how variables and data types are managed, focusing on the fact that even though Tcl can store everything as a string, internally it optimizes objects based on the way we access them throughout our code.

We also discussed object oriented programming and how Tcl 8.5 standardizes the approach and provides mechanisms for compatibility with other implementations of object-oriented programming in the Tcl world.

This chapter also goes through file-related operations—from reading and writing files, through file operations such as up to getting...

Left arrow icon Right arrow icon

Key benefits

  • 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

Description

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.

Who is this book for?

This book is for Tcl developers with basic network programming concepts, who want to add networking capabilities to their applications. Working knowledge of Tcl and basic experience of network protocols will be useful. The reader should be familiar with basic concepts used in modern networking – keywords like TCP, HTTP or XML should not be a mystery. The book does not require advanced knowledge of Tcl – the first chapters will swiftly introduce the reader into it, allowing refreshing the information or gaining a quick overview of the Tcl language abilities.

What you will learn

  • Get to know the the tools available to ease up development of Tcl code
  • Discover Tcl‚Äôs approach of using events over threads, which is very different from many other languages
  • Learn the VFS feature that allows the usage of Metakit database as normal file system
  • Create loggers, define log levels, write your logs to file or channel, and trace the execution of your code
  • Get to know the key differences between free TclPro Debugger and paid ActiveState Tcl Dev Kit Debugger
  • Handle different text encoding, dependent on the region you live, and create multi-language, internationalized application with msgcat package
  • Handle UDP communication in Tcl was presented, with TclUDP extension as the implementation
  • Manage files remotely over File Transfer Protocol (FTP) and learn to download a file from a web site using Hypertext Transfer Protocol (HTTP),
  • Learn the usage Lightweight Directory Access Protocol (LDAP) to look up information and/or authenticate users, manually querying host names and time servers
  • Get to know the Tcl package Scotty that handles SNMP and provides a Tk based GUI application that can be used for inspecting devices, discovering systems within our network and browsing data that can be retrieved over SNMP
  • Use Tcl code as legacy CGI scripts and improve it with ncgi package
  • Create client-server application based on HTTP protocol and Tclhttpd as embedded web server packed into Starkit technology for easy deployment
  • Connect to XML-RPC services and issue methods remotely, and easily integrate with major blogging engines
  • Create SOAP services using Tclhttpd and Web Services for Tcl; define complex data types for storing structured information
  • Learn to use encrypted connections from Tcl and the method to make sure you know whom your application is communicating with

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 01, 2010
Length: 588 pages
Edition : 1st
Language : English
ISBN-13 : 9781849510974
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 01, 2010
Length: 588 pages
Edition : 1st
Language : English
ISBN-13 : 9781849510974
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 209.97
Network Analysis using Wireshark Cookbook
S$74.99
Tcl 8.5 Network Programming
S$74.99
Tcl/Tk 8.5 Programming Cookbook
S$59.99
Total S$ 209.97 Stars icon

Table of Contents

13 Chapters
Introducing Tcl Chevron down icon Chevron up icon
Advanced Tcl Features Chevron down icon Chevron up icon
Tcl Standalone Binaries Chevron down icon Chevron up icon
Troubleshooting Tcl applications Chevron down icon Chevron up icon
Data Storage Chevron down icon Chevron up icon
Networking in Tcl Chevron down icon Chevron up icon
Using Common Internet Services Chevron down icon Chevron up icon
Using Additional Internet Services Chevron down icon Chevron up icon
Learning SNMP Chevron down icon Chevron up icon
Web Programming in Tcl Chevron down icon Chevron up icon
TclHttpd in Client-Server Applications Chevron down icon Chevron up icon
SOAP and XML-RPC Chevron down icon Chevron up icon
SSL and Security Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(7 Ratings)
5 star 57.1%
4 star 28.6%
3 star 0%
2 star 14.3%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Anthony Q. Jul 19, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good Book
Amazon Verified review Amazon
Amazon Customer Dec 17, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book! Most updated & most practical real world working examples I've found yet.... really thorough and excellent set of code sample's.
Amazon Verified review Amazon
Bernie Ongewe Dec 08, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I hardly see Tcl selected for network tasks any more but this manual reminded me of it's capabilities.The references to Ubuntu 9.04 also reminded me how old (by tech standards) this text is. Nonetheless, it remains one of the most complete treatments of Tcl that I've come across.
Amazon Verified review Amazon
Miguel Angel Perez Feb 18, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very good selection of the content, clear and concise explanations as long as the examples.I definitely recommend this book if you want to write fast and robust test applications using network.
Amazon Verified review Amazon
Todd Coram Sep 23, 2010
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
We need more Tcl books like this.I've used Tcl for years in unexpected places. I've found that Tcl is well suited for network centric applications.Yes, one of Tcl's great strengths lies in it's ability to manipulate network resources.However, when most people think of Tcl they think of Tk (GUI). This book shows a different side of Tcl. It starts off with a fairly comprehensive overview of Tcl (including advanced features) to prepare you for the network (and Web) centric latter half of the book.Most Tcl books are about the basics. This one is rare. It includes a lot of advanced topics not covered elsewhere. Plus, since it was published this year you'll find lots of up to date information.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.