Networking in Logo Ľubomír Salanci Department of Informatics Education Faculty of Mathematics, Physics and Informatics Comenius University, 842 48 Bratislava, Slovak Republic phone: +421 7 602 95 284 e-mail: salanci@fmph.uniba.sk web: www.edi.fmph.uniba.sk/salanci Abstract Similar to most modern programming environments, Imagine – new version of Logo – exploits communication and co-operation technologies. Imagine makes it possible to establish an on-line communication between two or several users located anywhere on the network. Imagine hides all technical problems concerning network connections and sending data thought the network. In a clear and intuitive way it is possible to send and receive any kind of Imagine data objects between connected users. It is possible to send Logo commands as well. Thus, for example turtle in one computer can be controlled from Imagine running in another remote computer. Utilizing this support, we can create simple yet rather effective network projects. In our paper we explore cooperation tools of Imagine and present several network projects. We also show how they can be extended into exciting network games. Keywords: Imagine, network, Internet, cooperation, programming, remote execution 1 Introduction Similar to most modern programming environments, Imagine allows users to exploit Internet network in several ways. A network support has been built into Imagine at several logical levels: Presentation level (tools for publishing Imagine projects on the Web) Direct manipulation level (tools for direct manipulating Web objects) Logo programming level (commands in Logo language to connect, control connection and transmit data) More information about about Imagine environment and programming language can be found in [1, 2, 4]. 2 The Presentation Level The presentation level is designed for wide range of Internet users. A project written in Imagine can be easily published as a Web page on the Internet by selecting File | Save as Web Project… in the main menu. Thus, anybody can see, try and play with published projects; only the Internet browser and installed Imagine plug-in are necessary. When a user saves his/her Imagine project as Web project, an applet and a simple html file that reads and displays the applet is generated by Imagine. At present, the plug-ins for Internet Explorer and Netscape Navigator are available free of charge. If you have not installed the plug-in yet, you are automatically offered to download it when displaying such a Web page for the first time. Some examples of published project are available at www.logo.com. Thanks to this technology, it is easy enough already for rather young children to present their projects on Web and allow anybody with appropriate Web browser and installed Imagine plug-in to explore and play with these projects. 3 Direct Manipulation Level The components developed to access Internet are of great help when creating and programming one’s own projects. The following components are accessible via Imagine’s main toolbar: Web Browser – displays the Web page inside your project Web Link – behaves like a button. When clicked, it opens browser window and displays the Web page the address of which is defined by the Web link Both components are very easy to use. The basic settings they offer help us to create simple and interesting projects without any programming. This is an example of a project which contains a Web Brower component and three Web Link components. Web Browser displays picture – a map of the actual weather of Slovakia from www.shmu.sk. Web Link buttons open window with detailed weather forecast for selected parts of Slovakia. 4 Logo Programming Level This is the level on which projects requiring a network communication are developed. The message passing via TCP/IP network protocol is supported by Imagine. It is an engine behind the Imagine that takes care about connecting, keeping connection up, sending and receiving packets etc. A programmer of Imagine projects is protected from these low level and technical details. Instead, he/she is offered a smart object class Net that makes it possible to: Establish client–server connections Recognize status of the connection and the list of actually connected users Send messages, data and objects easily Send programs and run their remote execution Process events and received data We will illustrate network object features of Imagine in the following examples: Establishing Communication among Several Computers Sending Text Sending Objects Remote Program Execution We will also explain language primitives on simple examples. 4.1 Establishing Communication Among Several Computers Let us have three computers and three users Alice, Bob and Jane sitting behind them. To recognize whose computer we are watching and what commands are being run there, we will write the commands into the named boxes (see bellow). First we will create the server object in the following way (let the Alice’s computer be a server): Alice ? new "Net [name a nickName Alice style server] ? a'connect By new "Net [Settings] new object of the class Net is created on Alice’s computer, Settings specifies that the name of the new object will be a, while nickname of this user will be Alice and the fact that her computer will be a server, By command a'connect the network connection of object a is created. After the server Alice is created, new clients can connect to Alice. To establish the connection, the server has to be identified either by its name or by its IP number (let the Alice’s name be alice.edi.sk): Bob ? new "Net [name b nickName Bob style client server alice.edi.sk] ? b'connect Jane ? new "Net [name x nickName Jane style client server alice.edi.sk] ? x'connect Now, the communication is established between all of the participants. Once the connection has been established, the computers are being identified only via their nicknames. It isn’t necessary any more to distinguish client and server when manipulating objects of the Net class. 4.2 Sending Text When Alice wants to send a simple text message to Bob, she will write: Alice ? a'send "Bob "|Hello Bob!| Bob can display the contents of the received message using his Net object b: Bob ? show b'message Hello Bob! Bob can recognize that he has received a message through the OnReceive event. It will be run automatically by Imagine immediately after any data has been received. Based on this knowledge it is easy to create simple chat program. 4.3 Sending Objects Similar to text, other data structures such as numbers and lists can also be sent via net. Moreover, we are also allowed to send the whole objects. Let us have the following situation: Alice has drawn interesting picture and has set it as a shape of a turtle t1. She wants to share her picture with her friends. That is why she sends the whole object to Bob. Alice ? a'sendObject "Bob "t1 Bob receives the object in a similar way as he received the text. Receiving the object means that the turtle with Alice’s drawing (for example, the shape of a flower) appears on Bob’s computer and is immediately displayed on his screen. While receiving data through a Net connection automatically generates the OnRecevie event, receiving object will runs the OnRecevieObject Bob ? b'receiveObject [] event. The user is allowed to react and control the process of receiving an object. Mechanism of sending objects is useful for building projects that develop cooperation between children. Running the project Building Bricks several users cooperate in building a structure out of several coloured bricks. The screen is divided into two parts – bottom one displays palette of colours and bricks, the upper part displays the structure. The user can select a brick and its colour and drag it into the upper part of the screen. This change is immediately sent to all other users. 4.4 Remote Program Execution Imagine makes it also possible to send a list of Logo instructions to another connected computer (or several connected computers) and make it be run there. Alice, for example, can send to Bob commands that will be executed on his computer only. Due to security, however, remote program execution has to be accepted by Bob first: Bob ? b'setRunEnabled "True Now, Alice is allowed to send commands to be executed on Bob’s computer: Alice ? a'sendRun "Bob [ask "t1 [repeat 200 [fd repc lt 91]]] Commands ask "t1 [repeat 200 [fd repc lt 91]] are executed on Bob’s computer and create well known spiral on his screen: Bob It is easy to see that the remote execution of Logo programs allows us: To control remote computers, To run independent processes on remote computers. 5 Additional Activities Illustrating Network Support Network capabilities of Imagine can be used for developing different kinds of activities, applications and projects. In this part we briefly present following illustrative activities: Object teleporting Distributed Computing Data Collecting Game Programming 5.1 Object Teleporting In previous chapters we described how objects can be sent via network in Imagine. In fact, it is a copy of the object, which is always being sent. Now we want to implement teleporting of objects. In object teleporting we will send a copy of an object to another computer and then erase the original one. Thus, only a copy of the original object will continue to exist. In this way we will “pretend” the effect that the object has been transferred from one computer to another. Teleporting is well known and rather popular process in science fiction and computer games as a way how to transport things, people and other objects from one place to another. Usually this is done through a special device called Teleport. It is easy to create a Teleport metaphor in Imagine. Whenever a user places an object into a Teleport, it will be transported to another (connected) computer. Alice Bob Jane The space ship is moving (in the bounce rangeStyle) along the screen. When it arrives at the teleport, it is transported to another computer. From now on the space ship exists and continues moving in the other computer. Here you can see a process of teleporting the space ship from the Alice’s computer to the computer of Jane captured in a series of three pictures (see the marked sequence of space ship's positions: 1, 2, … 6). Teleporting objects using the network of Imagine in the way we have just described is intuitively clear. It can be used in a lot of various activities based on sharing objects by connected multi users. 5.2 Distributed Computing This illustrates another group of interesting tasks suitable for experiments. The distributed computing takes place in the situations when the sequential algorithm is too much time consuming. If possible, the divide and conquer principle is applied then. The task is split into several independent parts that are solved on different computers. Then, the result is composed from all partial solutions. One such time consuming task is drawing a fractal. The possible distributed solution follows: Alice sends a program that solves the part of a task to Bob and other friends, The program computes the values of colours for specified line of a picture; these are sent back to Alice, It is Alice who is responsible for distributing of tasks and then handling the results. The figure illustrates the process of drawing the picture in detail. Some computers have completed their tasks more quickly, thus their results are received immediately. Some computers work slowly – therefore there are still some empty lines in the picture. 5.3 Data Collecting Another group of task we present here to demonstrate new feature of Imagine is oriented to data collection. Let us focus on statistical research – we are going to collect information about children's moods of today: We are using a Web page containing an Imagine applet. It displays several smilies with different faces and actual voting status. Each visitor of the Web page is allowed to vote by clicking some of the smilies. The actual data about voting are being sent to the server. The server is an Imagine project – a simple program that receives voting data and builds the statistics. Server will notify all active clients about results of voting after it will have processed the data. Left picture is a Web page with Imagine applet for voting. Picture to the right is a server – the Imagine project itself. 5.4 Game Programming Creating our own network games in Imagine is definitely one of the most challenging topics where network support can be exploited. It is easy to find different kinds of games where network can be utilized in several ways: In desktop games the game state and also information about which player’s turn is it must be sent there and back, In action games information about each object's movement must be sent, Games often have to share certain common information like game settings, high score table etc. Picture to the left shows very simple game for two players – TicTacToe. The network is utilised here to send information about which player's turn is it in the game. Picture to the right illustrates very simple action game – Tennis for two players. The network is utilised here for sending positions of objects in real-time, namely positions of both paddle and the ball. 6 Conclusion We presented network features built in new programming environment Imagine. Imagine allows us to send data, objects and Logo instructions via network. We illustrated these features in several activities and projects like object teleporting, distributed computing, data collecting and game programming. The Imagine network support is easy to use and interesting to explore new Logo programming techniques. It stimulates users to communicate and cooperate together. Comaparing network support in Imagine and MSW Logo: Imagine MSWLogo web support primitive component no e-mail yes yes other internet services no yes number of connections any up to 2 sending/receiving texts and data yes yes sending/receiving objects yes no remote program execution yes (using primitive command) yes (requires additional programming) ease of use simple (1 to 2 command line instructions) more advanced programming References [1] Blaho A and Kalas I (2001) Object Metaphor Helps Create Simple Logo Projects. To appear in Proc. of EuroLogo 2001 [2] Kalas I and Blaho A (2000) Imagine… a new Generation of Logo: Programmable Pictures Proc. of WCC2000, Educational Uses of Information and Communication Technologies, Beijing 2000, pp. 427 – 430 [3] Zaveršnik M and Batagelj V (1999) Networking in MSWLogo. Proc. of EuroLogo 1999, Sofia, pp. 127 – 134 [4] www.logo.com