5 Connecting several computersIn lesson 4 we learned how to connect two running Imagines via Internet. Now we will connect several computers. Participants of this connection will send messages to other participants - specifying all or one or several addressees. We will use the Change net1 dialogue box for setting the connection. After this, however, we will close the dialogue box and use only the Logo language constructions to make use of the net object. The reason for this is that more and more often (in the lessons to come) we will develop more complex Imagine projects in which we will need Logo language commands to control the network connection from our procedures. Let the first player - "host of the activity" - initiate the connection by creating the empty Net object (other initial settings will be done within his/her Change net1 dialogue box):
First player (host of the activity) should now open his/her Change net1 dialogue box and take there the following steps:
In this way first player (the initiator or host of the connection) has created a connection and waits for other players to join in - some of them either from the same local network, others through Internet. We know already that to join in, the player has to know the "address" of the first player's computer (a kind of its "telephone number"), that is, either the name of the computer or its IP address. Let it be the IP address 192.168.89.5 (a fictional example). Therefore the second player types in his/her command line:
Then he/she opens the Change net1 dialogue box and takes there the following steps:
Other players who want to join this connection should do exactly the same - regardless of their location. Remember that all joining players must connect to the same computer - the computer of the first player (host of the activity). In our example, this is the computer with the IP address 192.168.89.5. In spite of this, any participant of this connection will be allowed to communicate directly with any other participant, see the figure below. So what is the difference between the first player (the host or initiator of the activity) and other players within one connection? If considered from the point of view of using the connection for communication, we should say there is no difference at all. The only important difference to be aware of is the following:
All participants of the connection may keep their Change net1 dialogue boxes open and continue setting the connection from here (for example they can send a sample message from the Connection tab, they may observe who are the other participants of the connection, or on the Basics tab they can check whether they are already connected, they can specify the onReceive event here etc.). Let us however proceed in another way - using the Imagine Logo language commands (at present from the command line but later also from user-defined procedures). Therefore all participants should now close their Change net1 dialogue boxes and continue from the command line. Watch carefully the following language constructions:
Note that in several examples above we specified different addressees of the message in the net1'send … command. First input of the send command can be:
ConclusionWe connected several computers in one net connection. We learned that there is nearly no difference between the initiator (host) of the activity and all other participants. Any participant can directly1 communicate with anybody else. We have also seen how the net object can be controlled by the Logo language constructions. We will need this in developing (programming) more complex network applications in Imagine.1In fact, at the lower level this communication goes to its addressee through the host's computer. |