SWT (Squeak Web Toolkit) - Something else to show: Ping-Pong Things are taking fomar and now its framework (SWT) allows us to make some funny examples. I'll show you one of the examples in SWT: Ping Pong.
Ping-Pong's example is, I believe, the most simple to use SWT, which in turn displays the interesting features of the framework.
Uhhh ... much introduction ... better go straight to the point.
use the framework to begin creating 2 classes: SWTPingPongClientApplication and SWTPingPongServerApplication .
The first ( SWTPingPongClientApplication ) is a subclass of SWTClientApplication . The second ( SWTPingPongServerApplication ) is a subclass of SWTServerApplication .
According to SWT, an "application" is split between his party and his party Client Server. the client (in our example: SWTPingPongClientApplication ) is translated into JavaScript code (using the ST2JS) and runs in the Internet browser. In addition, the Server ( SWTPingPongServerApplication ) runs in Squeak.
for each browser (Internet) connected, have a couple of instances (the Server and Client) that remain "united" by the framework.
When we are on the client, can send messages to the Server in the following way: Similarly, when we are in the Server can send messages to the Client as follows:
-
The Client part, to send the message
# ServerSide , it returns a proxy that forwards messages to Squeak using JSON-RPC. In addition, the Server, when we send the message
# clientside returns a proxy that forwards messages received, the client, using the Comet connection.
-
- This we already know enough to see the sample code Ping-Pong.
-
- the client side of our example ( SWTPingPongClientApplication ) has only 2 methods, see the first:
initializeWidgets "Initialize the receiver's widgets" contents: 'Ping Pong' ). root addWidget: ( SWTButton caption: 'ping server' onClick: [ : event ] ). Allí vemos como se crean 2 widgets: Un Header y un Button. Si, lo sé... no es nada espectacular... pero lo interesante está dentro del evento #onClick del botón: self serverSide ping Cuando hagamos click sobre el botón, el mensaje #ping se evaluará, ¡pero del lado del servidor!. Veamos entonces la implementación de #ping in the Server ( SWTPingPongServerApplication ). ping Transcript show: 'ping! " ; |
cr.
self
-
-
clientside pong. |
This method, and show something in the Transcript, returns the "favor" to his counterpart in the last line Client.
- Now, finally, consider the implementation of Client side # pong (
SWTPingPongClientApplication ).
-
- pong
^ self inform : "pong!" If u like, watch this Screencast
|