Channels ▼


Green Telnet

Source Code Accompanies This Article. Download It Now.

Changes to the Telnet Client

The telnet client has two major changes. Similar to the server, the client has a rolling byte count that keeps track of how many bytes of data it has received from the server. More importantly, however, the telnet client also has a thread that receives notification from the host operating system when the (client) machine changes power state. For the client to notify the server of changes in power state, the client must receive these changes from the host operating system. We have provided two possible implementations for this. The first implementation works on Ubuntu Linux and utilizes a script that is invoked by the host operating system's sleep and wake power management scripts. The script simply connects to each running client and passes the state change on. Our second implementation utilizes the power management API of Mac OS X. In this case, the client receives power state change notification directly from the operating system. Once the client has been made aware of a change in power state, it simply passes the notification up to the server with a gtWSLE or gtWWAK message.

When the client wakes up, it reconnects to the server and performs a two-step information exchange before normal communication resumes. As in Figure 1, the client first receives the next reconnect port number from the server. The client then sends the server its byte count, which the server uses to calculate any data discrepancies. The client then resumes normal operation. If the server determines that any data has to be resent to the client, the client receives it via normal communication channels. That is, while the data may have originally been sent by the server prior to the client going to sleep, if the client missed this data for any reason it is simply resent in the normal manner after the client wakes up.

gtelnetd in Action

Figure 4 shows gtelnetd in action. Three clients are connected to an IRC server and chatting in the same room. Chatter "Alice" stays connected to the server the entire time, chatter "Bob" is using the gtelnet client, and chatter "Charlie" is using a regular telnet client. Both Bob and Charlie are logged into a shell account from which they run their respective IRC clients. At 05:33pm, Alice sees both Bob and Charlie enter the chat room. After some initial conversation, both Bob and Charlie send their machines to sleep at 05:35pm. Alice receives a message indicating that Charlie has disconnected from the IRC server due to a dropped TCP connection to the server he is running his IRC client on. Bob, however, effectively never leaves the chat room due to his usage of the gtelnet client. When his machine goes to sleep, the gtelnetd server buffers all data that is transmitted. When Bob wakes-up his machine at 05:44pm, he sees the messages that Alice transmitted when his machine was asleep. Charlie, however, reconnects at 05:46pm and has not received any of the chatting that took place between 05:35pm and 05:46pm.

Figure 4: gtelnetd in action.

Next Steps: Spreading the Meme

The developed gtelnetd is a useable application. All source code is available at and contributions are welcome. The techniques applied in the creation of gtelnet can be used in other client/server applications. Any interactive program in which data might be generated and delivery desirable, even though a user may not wish to respond in real time, is ripe for making power-state aware. While telnet is not used often anymore, SSH is popular and implementing power-state aware functionality should be very similar to our green telnet modifications. Instant messaging applications are another set of software in which clients may want to receive messages sent while the machine sleeps.

A Lawrence Berkeley National Laboratory technical report ( stated that, "proper functioning of power management would achieve additional savings of 17 TWh/year." At $0.10 per kWh, this is $1.7 billion per year—a very large savings potential! Many, if not most, desktop computers have power management completely disabled due to the inconvenience it causes to users. By removing the application state's dependency on a network connection as we have done with gtelnetd, users will be less inclined to disable power management. This can result in large savings of money and also reduce the CO2 footprint of PCs.


The development of this material is based on work supported by the National Science Foundation under grant CNS-0520081. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author and do not necessarily reflects the views of the National Science Foundation (NSF). The authors thank Axel Vigo from the University of Puerto Rico, Mayaguez for his early prototypes of green client/server applications.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.