Examples

Explore some live examples of Wt below.

The source code of these (and many more) examples is included in the Wt source distribution. You may also browse through the source code of each example using the source code viewer, following the link below each example.

Cross-linked source code for these examples is also in doxygen documentation (in a new window).

Simple Chat

Run example (or ventilate your thoughts down here)

This example implements a simple chat client and server. Using server-initiated updates, you can easily push events from one user to other users. Server-initiated updates are implemented using Ajax long polling or HTML5 WebSockets.

It also illustrates nice benefits of a class-based approach to web application development: you can easily instantiate the same widget class multiple times. The SimpleChatClient widget may be reused just as you reuse basic Wt widgets such as a push button.

The chat application is also available as a Widget which can be embedded in another page (very much like how you integrate a google maps widget inside another application). In this case, we've embedded the chat also in this very homepage as follows:

    <div id="chat"></div>
    <script src="http://www.webtoolkit.eu/wt/examples/simplechat/chat.js?div=chat"></script>

This uses Cross-Origin Ajax/WebSocket requests (if the browser supports this, falling back to old tricks if not) to communicate from a HTML origin page to a server hosting the Widget possibly from a different domain.

Interactive applications like these, which allow users to post HTML text to other users, are notorious for cross-site-scripting (XSS) attacks: a user enters malicious (javascript) code as part of his message. When another user renders this message, it may transmit unwanted private information retrieved from, for example, browser cookies. Wt prevents such attacks completely, and without any responsibility to the developer, since widgets such as WText ensure that what is displayed is only passive text, discarding anything that is not strictly text.

Browse the source code