Exploring the Sample Code

The sample applications provide fully functional examples of how to implement key methods of the PureWeb APIs, as described below.

Scribble

All flavors of the Scribble sample application implement the same basic concepts:

  • The canvas where users draw lines is an example of a view. When you draw in the browser window, you are actually sending commands to draw on the service application, and what is drawn there is mirrored as a remoted image in the view.
  • When you interact with the view, the input event is captured automatically by the view's IRenderedView interface. This interface's postKeyEvent and postMouseEvent functions are used to map the user input to the service-side functionality. The code for implementing this is discussed in User Input Events.
  • The quality of the image on the canvas is lower while you are drawing than when you are not. This is because the interactivity mode is enabled in the Scribble view, allowing the service to send images with different encoding during user interaction. How to implement this is discussed in Defining Image Encoding and Quality.
  • When you pick a different drawing color, the change is handled using application state. In the sample code, you'll notice how the native elements of the development platform were used to create the UI element provided for selecting the color.
  • When you clear the screen by clicking the Erase All button or menu option, the service responds by clearing the screen (in other words, sending an updated view of the canvas). This functionality is implemented using a command.
  • The Share button is used for collaboration. When the end user clicks this button, the client application will display a URL that can be copied and sent to someone else. A second user can then use this URL to navigate to the active session and join in.
  • The Diagnostics Panel provides a set of tools for debugging the client.

Asteroids

All flavors of the Asteroids sample application implement the same basic concepts:

  • The main window where users play the game is an example of a view.
  • Whenever you interact with the view (change the heading, fire torpedoes, etc.), the input event is captured automatically by the view's IRenderedView interface. This interface's postKeyEvent and postMouseEvent functions are used to map the user input to the service-side functionality. The code for implementing this is discussed in User Input Events.
  • Whenever the end user shares the screen by clicking the Share button or menu option, the service responds by displaying a share URL. This functionality is implemented using a command. The Share interface element has been added to the view using the native elements of the client development platform.
  • The Share button is used for collaboration. When the end user clicks this button, the client application will display a URL that can be copied and sent to someone else. A second user can then use this URL to navigate to the active session and join in.
  • The level reached by the player is an example of a user-defined element stored in the application state tree.
  • The Diagnostics Panel provides a set of tools for debugging the client.

Path to Sample Code

If you want to explore the source code of the sample applications, you will find the files at the locations listed below.

Services

C++

  • On Windows: [installed_location]\SDK\Samples\Scribble\ScribbleAppcpp
  • On Linux: [installed_location]/SDK/Samples/Scribble/ScribbleAppQt

C#

  • [installed_location]\SDK\Samples\Scribble\ScribbleApp

Java

  • Scribble: [installed_location]\SDK\Samples\Java\src\server\pureweb\samples\scribbleapp
  • Asteroids: [installed_location]\SDK\Samples\Java\src\server\pureweb\samples\asteroids

Clients

HTML5

  • Scribble: [installed_location]\SDK\Samples\Scribble\ScribbleClientHTML5
  • Asteroids: [installed_location]\SDK\Samples\Asteroids\AsteroidsClientHTML5

iOS

The PureWeb Framework is deployed through CocoaPods. You can find the Framework in the Pods project:

Android

  • [installed_location]\SDK\Samples\Android
    There is one subfolder for Scribble, one for Asteroids, and a pureweb subfolder for the code common to both applications.

Flex

  • [installed_location]\SDK\Samples\Scribble\ScribbleClientFlex

Java Swing

  • Scribble: [installed_location]\SDK\Samples\Java\src\client\pureweb\samples\scribblesapp
  • Asteroids: [installed_location]\SDK\Samples\Java\src\client\pureweb\samples\asteroidsapp

Silverlight

  • [installed_location]\SDK\Samples\Scribble\ScribbleClient