MaDKit forum

Welcome All !
Please, use explicit topic names when creating new threads. Thanks.

You are not logged in.

#1 2018-01-23 18:19:19

bgateau
Member
From: Luxembourg
Registered: 2018-01-23
Posts: 6

How to create a distributed society?

Hello,

I would like to know if it is possible to create a distributed society. I mean a society with agents on different hosts. And how to send message between those distributed agents?

Regards

Offline

#2 2018-01-24 11:03:00

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to create a distributed society?

Hello,

bgateau wrote:

I would like to know if it is possible to create a distributed society. I mean a society with agents on different hosts. And how to send message between those distributed agents?
Regards

Yes it is possible. To try it out quickly on a single host, you can use the desktop mode and just launch one instance of, for the example, "PingPong". Then start the network mode (in the menu or icon). Then just redo this with another instance of the desktop : The two MDK kernels should automatically connect and the PingPong agents should see each other right after that.

In fact, agents do not have to care about where the other agents are when sending messages : groups and roles are the only things that matter for message passing. Of course it is possible to know that another agent is on the same host or not but it is not something crucial here.

So, MaDKit kernels automatically connect to one another on a LAN, and you should be able to repeat this on different hosts easily.  A distant host on a WAN can be added using the dialog box).

To enable the network mode by default when launching MaDKit, you should use the --network option.

Notice that you may encounter an issue if you have a virtual network interface installed on the host (such as the one which is installed by docker or similar softs)

Best regards,

Offline

#3 2018-01-24 16:11:49

bgateau
Member
From: Luxembourg
Registered: 2018-01-23
Posts: 6

Re: How to create a distributed society?

Hello,

Thanks for your answer. Just before checking your message, I saw in the Desktop instance of MaDKit 3 menu items dealing with network. Than I read your message.

Unfortunately, I didn't success to execute your example. As you said, I launched two instances of MaDKit desktop, launched network on both instances and started a PingPong agent on each ... and nothing happened. They didn't communicate.

Besides, is there another way to launch network and connect two kernels (on the same host or not) without using an instance of the desktop. My goal is to launch an agent on a computer linked to the network and make it communicate with others agents on others hosts.

I will continue to investigate by firstly studying tutorials.

Regards

Benjamin

Offline

#4 2018-01-24 16:35:37

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to create a distributed society?

Hello,

bgateau wrote:

Thanks for your answer. Just before checking your message, I saw in the Desktop instance of MaDKit 3 menu items dealing with network. Than I read your message.

MaDKit 3 ? You meant 5, right ?

bgateau wrote:

Unfortunately, I didn't success to execute your example. As you said, I launched two instances of MaDKit desktop, launched network on both instances and started a PingPong agent on each ... and nothing happened. They didn't communicate.

If everything is OK, and without launching any agent at all, small "network icons" should first appear on the top right of the window.

bgateau wrote:

Besides, is there another way to launch network and connect two kernels (on the same host or not) without using an instance of the desktop. My goal is to launch an agent on a computer linked to the network and make it communicate with others agents on others hosts.

There are several ways possible indeed. the desktop is just about quickly having a menu to launch some agents but is not required at all. The network could be activated at startup or during the execution, even by the agents by sending a message to the kernel agent

bgateau wrote:

I will continue to investigate by firstly studying tutorials.

Great, it will be then indeed easier for you to understand how MaDKit works.

Regards,

Offline

#5 2018-01-24 16:49:36

bgateau
Member
From: Luxembourg
Registered: 2018-01-23
Posts: 6

Re: How to create a distributed society?

fmichel wrote:

Hello,

bgateau wrote:

Thanks for your answer. Just before checking your message, I saw in the Desktop instance of MaDKit 3 menu items dealing with network. Than I read your message.

MaDKit 3 ? You meant 5, right ?

I use MaDKit 5 indeed, but I meant that in the window of the MaDKit desktop, I saw 3 menu items: "launch network", "stop network" and "connect to IP" ! And I think that I will need to use the "connect to IP" command to make an agent of HOST1 (my laptop) able to communicate with agent of HOST2 (my desktop computer).

Benjamin

Offline

#6 2018-01-30 10:44:42

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to create a distributed society?

bgateau wrote:

I use MaDKit 5 indeed, but I meant that in the window of the MaDKit desktop, I saw 3 menu items: "launch network", "stop network" and "connect to IP" !

Of course, my mistake.

bgateau wrote:

And I think that I will need to use the "connect to IP" command to make an agent of HOST1 (my laptop) able to communicate with agent of HOST2 (my desktop computer).

"launch network" starts the "network agent" and put the kernel online and thus make it available for receiving connections. It should also automatically connect to other kernels which are on the same LAN. "Connect to IP" is more about reaching hosts located on the WAN, but could also indeed be used to connect to any host thanks to its IP.

Fabien

Offline

#7 2018-01-30 12:19:16

bgateau
Member
From: Luxembourg
Registered: 2018-01-23
Posts: 6

Re: How to create a distributed society?

fmichel wrote:

"launch network" starts the "network agent" and put the kernel online and thus make it available for receiving connections. It should also automatically connect to other kernels which are on the same LAN. "Connect to IP" is more about reaching hosts located on the WAN, but could also indeed be used to connect to any host thanks to its IP.

Hello,

OK, I launched to MaDKit platforms (kernels?) on two different computers. I launched one PingPong agent on each kernel and then I launched network on both. Then I connected one kernel to the other kernel with the "connect to IP" menu. And PingPong agent from one kernel succeed to automatically communicate with the PingPong agent from the other kernel. I launched more agents on both platforms and every agents played with all agents.

But I did that with the MaDKit Desktop (with the menu). Is it possible in the "main(String[] args)" (or somewhere else) of the PingPong java class to add a method or argument to make the kernel of the agent this object will launch connect automatically to another kernel (a kind of broker one) and have for instance:

public static void main(String[] args) {
    String[] argss = { "--network", "--launchAgents", "--connectToIP", "10.122.10.64", PingPong.class.getName(), ",true" };
    Madkit.main(argss);
}

Thanks for your time.

Benjamin

or

public static void main(String[] args) {
    executeThisAgent(1, true, "10.122.10.64");
}

Offline

#8 2018-01-30 17:18:38

bgateau
Member
From: Luxembourg
Registered: 2018-01-23
Posts: 6

Re: How to create a distributed society?

Hello again,

I create a PingPongNet class extending the PingPong class as following:

public class PingPongNet extends PingPong {

	public String ip = "10.122.10.74"; 
	
	public void activate() {
		super.activate();
		getLogger().info("I just activated the agent");
    	
		try {
			this.sendMessage(LocalCommunity.NAME, Groups.SYSTEM, DefaultMaDKitRoles.GROUP_MANAGER_ROLE,
					new KernelMessage(KernelAction.CONNECT_TO_IP, InetAddress.getByName(ip)));
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		String[] argss = { "--network", "--launchAgents", PingPongNet.class.getName(), ",true" };
		Madkit.main(argss);
	    }
}

And when I launch this agent, it automatically launch the network and also connect the kernel in which it is to the kernel having the IP stored in variable "ip" ... and it is work! Both agents interact and play ping-pong.

What do you think? Is it a good way to do it? Or something better is possible? I found the command to connect to another host in the class dealing with the menu of the GUI.

Benjamin

Offline

#9 2018-02-06 11:04:41

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to create a distributed society?

Hello Benjamin,

Sorry, I was very busy these last days.

--connnectToIp is indeed clearly missing from the options one can pass to the command line and I will add it in the next release.

Anyway, I see that you found your way in the Javadoc, which is great !
And your solution is very good as it works !

You may also try this in your agent, which may be more direct/reusable (same process under the hood) :

        javax.swing.Action connect;
	try {
	    connect = KernelAction.CONNECT_TO_IP.getActionFor(this, InetAddress.getByName("10.122.10.74"));
	}
	catch(UnknownHostException e) {
	    e.printStackTrace();
	}
	connect.actionPerformed(null);

Not tested recently but it should work.

Fabien

Offline

#10 2018-02-12 14:43:21

bgateau
Member
From: Luxembourg
Registered: 2018-01-23
Posts: 6

Re: How to create a distributed society?

I tested your version and it works also.

Benjamin

Offline

Board footer