1 Connecting Two Imagines

This tutorial is an introduction to using a network in Imagine. We will learn how to:

  • Connect two running Imagines together
  • Send a simple text message
To make the introduction into Imagine networking as simple as possible, we will connect the Imagines locally - running them on the same computer.

1. Let us launch two Imagines. It is necessary to launch them with /m command line options:

launchmultiple

2. Restore their windows to normal size and arrange them next to each other:

Two Imagines

Now we have two windows of Imagine - let us call them the Left and the Right Imagine.

3. Now, we connect these Imagines together using the Net object. This connection is done locally on the same computer. It allows easy testing and observing what is happening.

We start with the Left Imagine window. It will be the server Imagine project. To make it server we type the following commands into the command line:

  • new "Net [style server]
This instruction creates new networking object and gives it the name - net1. Its style will be server.
  • net1'connect
This instruction activates net1 object and connects it to the network.

create server

Networking object net1 allows us to connect two or more Imagines together, to send data between them, check the network status etc.

At this moment we may connect the Right Imagine. The Right Imagine will be the client Imagine and it will be connected to the server. We write to the Right Imagine:

  • new "Net [style client server localhost]
  • net1'connect

create client

First instruction has created new networking object named net1 in the Right Imagine. Its style is client, that is, it behaves as a client connected to the local computer. Its server setting is localhost. Second instruction has activated net1 object in the Right Imagine and has connected it to the network.

4. At this moment we have the Left Imagine and Right Imagine connected together. We may check this connection by asking for the list of currently connected users. We can type the following instruction into the Left and Right Imagine as well:

  • show net1'users
Show all users currently connected to net1 networking object.

check users

If everything works correctly, the result of this command should be [server client].

5. It is possible to send a simple text message via net. Let us send "Hello" text from the Right Imagine to the Left Imagine (of course, the same is possible vice-versa as well):

  • net1'send [] [Hello]
Through object net1 we send the list [Hello]. The empty list [] means we are sending the list to all users of this connection except us.

sending text

This text was sent to all currently connected users except the sender himself/herself (now, it is only the Left Imagine).

Now, the Left Imagine should display received message:

  • show net1'message
Take the received message from buffer and show it in the text screen.

receiving text

This command will show [Hello] in the text screen of the Left Imagine.

Conclusion

It is very easy to connect two Imagines which are running in one computer in parallel. When you are going to send and receive texts, two commands are sufficient to know - namely, send and message. Connecting two Imagines locally is very useful for getting first experience and running your own introductory experiments. We will see that establishing connection between two computers is very similar to the steps described above.