TCL 8.5 NETWORK PROGRAMMING PDF

adminComment(0)
    Contents:

Tcl Network ProgrammingBuild network-aware applications using Tcl, a powerful dynamic programming languageWojci. 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. [PDF] Tcl Network Programming: Build network-aware applications using Tcl, a powerful dynamic programming language. Tcl Network Programming.


Tcl 8.5 Network Programming Pdf

Author:ELNORA ODMARK
Language:English, Indonesian, Dutch
Country:Grenada
Genre:Environment
Pages:625
Published (Last):29.07.2015
ISBN:665-4-18832-212-6
ePub File Size:17.70 MB
PDF File Size:20.81 MB
Distribution:Free* [*Sign up for free]
Downloads:48081
Uploaded by: SHERLEY

s Effective Tcl/Tk Programming Web-based Tcl/Tk Courses available: s The pppstats program prints out statistics for a PPP network connection s We can. P U B L I S H I N G community experience distilled Tcl Network Programming Wojciech Kocjan Piotr Beltowski Chapter No.7 "Using Common Internet. Tcl Network Programming pdf download | PDF RAR Tcl Network Programming by Wojciech Kocjan and Piotr Beltowski Packt Publishing.

All the data types in Tcl can be treated as strings because, in an important way, they are strings. Even source code can be manipulated as a string.

The integer 2 and the string "2" are the same value. The value 2 is an integer when passed as an argument to a command that is meaningful for integers. If "hello" is passed to a command that treats the argument like an integer, the result will either be nonsense or an error. It is up to the programmer to make sure that the right values are passed as arguments. This means that Tcl values are fundamentally polymorphic.

Additionally, code can be generated, inspected, and manipulated like any other data. These features enable powerful introspection and metaprogramming techniques. Syntax The syntax of the language is very simple, and resembles the Bash scripting language : an unadorned command followed by one or more arguments, separated by spaces. Curly brackets are used to set off arguments which need to include spaces in them that is, inside braces, spaces are not word delimiters.

This is a comment.

Comments begin with the hash sign. The interpreter always reads the first line as a command name, and treats each additional item on the line as an argument to that command. Thanks to this we'll only need to build the message parts and combine them into a final message. This command accepts one or more options and returns a new token that identifies the new MIME part. Based on the options specified, there are two modes in which it can be used the first is to parse content such as parse a received message , and the second is to create content.

We will focus on the second case and leave parsing for sections that talk about receiving. Whenever we want to create a MIME part we need to specify the -canonical option and provide the content type for this part. Type is the MIME type described earlier. There are three possibilities for creating MIME objects from a file or from a string, and when creating multipart content.

To create it from a file or a string, we need to specify the -file or -string option and provide either the path to the file or the content of this part as string or binary data.

We should also specify the -encoding option that states how content should be handled so that it can be passed over a 7-bit protocol such as SMTP. For binary files, we should usually use base64 encoding and for text files, it is best to use quoted-printable. When creating a MIME part, we can also specify one or more headers that it should have by adding the -header option.

This option can be specified multiple times and each parameter to this option should be a list containing a header name and corresponding value.

These headers are then added to the actual MIME body. Their names and corresponding values are part of MIME's specifications. We'll cover a small subset that we need to know in order to send an with both inlined elements and attachments.

The value for this option should contain a list of all parts that should be included in this multipart content. Parts are included in the same order as provided in the list. Let's walk through an exercise of building up an that we described earlier.

This code uses several files, mainly message.

The files as well as the complete source code for the example in this section are located in the 01mime directory in the source code examples for this chapter. There are three types of elements that we are building: HTML and plain text messages: Their context is defined by multipart elements they are included in, therefore, we only need to define content type.

JPEG image: It is an attachment, therefore, we need to provide more information in the part headers filename, Content-ID, and disposition. Multipart elements: These are used to combine other types of elements into a structure that we've described earlier. Sending text messages also relates to character sets, encodings, and issues with internationalization. When sending messages that contain characters outside of 7-bit ASCII, we need to be aware of two things.

First of all, Tcl sends both strings and file contents in binary form. If we want to send text from a file, then that file needs to be encoded properly, using encodings such as UTF If we want to send text from Tcl, we need to convert that text to proper encoding. The command encoding convertto converts text to specified encoding and is described in more detail in Chapter 4. For more information about standardized character encodings, please refer to: character-sets.

Tcl 8.5 Network Programming

Next we have an inlined image in this case, we need to define additional headers. The first header is Content-Disposition, which specifies how this part should be handled.

Specifying inline means that this is an element that will be referenced from the main document and should not be shown as an attachment.

The second header is Content-ID, which identifies and names an element. This is how an element can then be referenced from other parts.

For example, our message. Content-ID in this case specifies an attachment name and should be the same as the filename specified in the Content-Disposition header.

This is how the attachment. There is also a difference between naming parts within an and actual filenames. However, this example names files from MIME's perspective in the same way as files are named on disk. This prevents poorly written applications from having issues with forwarding or replying to s with such images. It can be done using the uuid package and the uuid::uuid generate command, but any mechanism for generating a unique ID, such as from a related database entry, will work.

In order to delete all elements that are used in that element recursively, we can add the -subordinates option with the value all.

Information about all commands from mime package can be found in its documentation available at: Sending s Now that we're able to build MIME parts and the contents of messages, we can send our message.

This is the protocol that almost all applications use to send and all service providers give you an SMTP server to send messages through. From the Tcl perspective, we need to use the smtp package. This package uses the same tokens as MIME to send messages, which means that if you have created a message using the mime package, sending it requires only a few lines of code. The package smtp offers a single command smtp::sendmessage. This command requires passing a token to MIME part and accepts additional options.

The first one is -servers, which is a list of SMTP servers to try. If this is not specified, then message is sent using the SMTP server on the local machine.

If the machine our code is run on has an SMTP server, it is okay to not specify this option. If our SMTP server is using a non-standard port, the option -ports can be used to specify which ports we should try to connect to. For the majority of users, it is not necessary to use this flag.

Similar to the mime package, it accepts a list where the first element is the header name and the second is the value. For fields such as To and From, we need to specify addresses in a specific way.

If we want to specify both the full name and address, it should be in the form of "[Full Name]" If only the address is to be passed, it should be in the form of Multiple items should be separated by a comma succeeded by a space.

Specifying who the message should be delivered to can be done using the -recipients option. If -originator is not passed, the value is taken from the From or Resent-From header field.

If -recipients was not specified, the value is taken from the To, cc, Bcc, or Resent-To header fields and is concatenated to one list. Please note that only headers specified to smtp::sendmessage are parsed, not headers set in the MIME token provided to the command. If our SMTP server requires authentication, we will need to pass this information to the smtp::sendmessage command.

The options -username and -password can be used to specify credentials and if server requires authentication, the smtp package will use these. Usually authentication is needed if your server is being accessed remotely.

In these cases, the username and password are provided by your ISP or network administrators. Automated sending Now that we know how to send an from start to end, we can move on to more advanced issues.

Often our application will just send s sporadically. However, there are many applications that mainly send s. Many companies run their business by sending customized information to their customers and need a robust system that can send large volumes of s, which handles failures of servers and needs to be customizable from both business logic and template perspectives. If we plan on sending messages, we need to automate the process of building them and creating a system that will allow other people to customize both content and the appearance of our s.

We can either create a set of standalone tools or libraries that we can then use in our applications, depending on our needs. One of the most important things that such an application will offer is an easy way to change contents of messages easily. In many cases, it is enough to have a separate directory for content of a message along with standardized file naming. Creating template based s For example, let's assume our messages are stored in a separate directory.

Files called message. The subject of the message is in the subject. We'll also assume our messages are in UTF-8 encoding, which allows support for various encodings around the world. Let's start with creating a namespace, and create a procedure called readtext for reading text files. This procedure will also use the subst command to allow substitution of commands and variables. We can use it for passing data to our templates as dictionaries. For example, if we were to send a notification that a payment is due, data would contain first name, last name, and other information about the recipient, and the amount and payment date.

Our template would then include these values in the text by using dict get command as seen in this section. We've loaded the uuid and fileutil::magic::mimetype packages. The first one is used to generate the message's unique identifier, whereas the second one is used to get the MIME content type from files, so that these don't have to be specified explicitly by template providers.

It also accepts an optional list of attachments, which allows us to add additional files, such as invoices as PDF files, if this is needed. We'll also make sure that the subject does not include any newline characters as this will create errors when either building or parsing the message. We do this by splitting the subject into a list of lines and choose the first element from that list.

Please note that, at this point, our messages are already formatted using the data that was provided. This step is very similar to how it was previously built for our first message.

We create a list of parts and add only one element to it for now the actual HTML part. The variable file contains full path to the file and filename contains just the filename. We initialize it to just one element the result from previous step, the complete message containing plaintext, HTML, and images added inline.

Kundrecensioner

Now we iterate through the list of attachments, taking two elements from the list at a time. The first one is the path to attachment file and the second one is the name that will be shown to the recipients. Setting the Subject header before sending the message is different from the previous example.

Although the From, To, Cc and Bcc fields should be set during the smtp:: sendmessage step, Subject and all other headers that are not related to message delivery can be set before sending the message. We're also passing two values to the message firstname and lastname.

It has to contain subject. The directory can also contain files that should be embedded as part of the message. The list provided as the last argument is the list of attachments to include. While the actual file is called attachment. The example in this section is located in the 03 template directory in the source code examples for this chapter. It also contains a sample template that uses data variables for passing information. Documentation on mime and smtp packages can be found on the tcllib project website at SourceForge: and Receiving s In many cases, apart from sending s, our application should also be able to receive messages sent via.

One example is that if we send out mass s to users, we might also want to be able to receive messages for unsubscribing from them and process them.

Also, our application can also receive "delivery failed" notifications and process them for example, starting with temporarily not sending messages and ending with removing failing addresses from our records permanently.

One of the most flexible options is to set up a dedicated SMTP server that will accept s from other systems. This option, however, requires more setup and is discussed in the next chapter. A simpler option that will allow us to receive s is to use existing servers and read s from them. In order to read over POP3, we need to know the POP3 server name, and the username and password required to access our account.

Usually, this is provided by our system administrators. POP3 works so that applications connect, list and read messages, delete the ones they have already read, and then disconnect.

This is then repeated periodically. POP3 uses positive integers to identify all messages. These messages range from 1 to the number of messages therefore, if our inbox has 23 messages, they are 1, 2, 3, Throughout the entire connection to a POP3 server, each number is guaranteed to point to the same message. Therefore, until we disconnect, message 19 will always point to the same message. If we delete a message, we can no longer reference that particular message, but all other messages will still have the same index for example, if we delete message 4, messages from 5 and up will still have the same identifiers.

Tcl Programming Examples, Tutorials, and More

Also, when new messages arrive during our connection to the server, our connection will not be able to access them. POP3 is designed so that the application logs in, reads messages, and disconnects. Our program might be doing this frequently, but it should always set up a new connection to the server.

In order to initialize a connection, we need to run the popopen command by providing it with the hostname, username, and password. Optionally, we can specify the TCP port to connect to as the next argument, otherwise the POP3 default port is the used. This command returns a channel that is used by all other commands from this package.

For example, the following will connect to your Gmail account: set h [popopen "pop. This token is used by all other commands from the pop3 package and is always passed to these commands as the first argument. The first one is -socketcmd, which allows us to specify the command that should be used for creating the socket. Its main use is to support Secure Socket Layer SSL and for providing a command that connects using a proxy server if this is needed.

For example: set h [popopen socketcmd tls::socket "pop.If this is the case, the POP3 package needs to work around some non-standard behavior that occurs when communicating with a Microsoft Exchange server. Tcl is regarded as one of the best-kept secrets in the software industry.

This package allows the building and parsing of messages and handles all aspects of a message headers, content, and support for multipart messages. Optionally, we can specify the TCP port to connect to as the next argument, otherwise the POP3 default port is the used.

ClickShare Network Integration Application note 1 Introduction ClickShare Network Integration aims at deploying ClickShare in larger organizations without interfering with the existing wireless network. These features enable powerful introspection and metaprogramming techniques. Learning Nagios - Third Edition. John A. If two indexes are specified, then multiple messages are deleted.

Event loop and various types of events are also discussed.

SHONDRA from Akron
Browse my other articles. I am highly influenced by risk. I enjoy reading books verbally.
>