5 Connecting several computers

In 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):

  • new "Net []

First player (host of the activity) should now open his/her Change net1 dialogue box and take there the following steps:

  • set the Style setting to Server,
  • then replace the default Nickname (this is optional but recommended) for example to Marta,
  • and finally click the Connect button.

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:

  • new "Net []

Then he/she opens the Change net1 dialogue box and takes there the following steps:

  • set the Style setting to Client,
  • then replace the default Nickname (this is optional but recommended) for example to Andrea,
  • in the Server edit box type in the address of the first player's computer, in our example the IP address 192.168.89.5,
  • and finally click the Connect button.

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:

  • if the first player closes the connection - either by the net1'disconnect command or within his/her Change net1 dialogue box by pushing the Disconnect button - the whole connection will be canceled - for all players,
  • if any other player leaves the connection, it's only him/her who leaves and nothing else happens. The connection continues to work for all other participants. New player or even the one who has just left can connect in again into the same properly working connection.

net of 4
First player - host of the activity - initiated the network connection, and then several other players have joined it. From that moment every participant can communicate with any other participant or a group of other participants.

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:

Am I already connected? print net1'connected?
true
Who are all participants of this connection? print net1'users
[Marta Andrea Peter Zsuza … ]
I want to set the onReceive event of my net1 object to print message (later we will run into situations when this will have to be done from our running program): net1'setEvent "onReceive [print message]
Note that the same can be done on the Basics tab of the Change net1 dialogue box. There we would type print message directly in the onReceive event edit box.
I want to send a message to all participants of the connection except me: net1'send [] [This is my message]
I want to send a message to all participants of the connection including myself: net1'send net1'users [This is my message]
I want to send a message only to Peter: net1'send [Peter] [This is my message]
I want to send a message to Peter and Andrea: net1'send [Peter Andrea] [This is my message]
What "role" does my computer play in this connection? print net1'style
client

This means that I am not the initiator (host) of this activity.
I want to leave this connection: net1'disconnect

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:

  • A participant - that is a nickname of a participant of this connection.
  • A list of participants - that is a list of their nicknames.
  • An empty list to address all participants of the connection except yourself.

Conclusion

We 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.