Table Of Contents

Previous topic

6.1. Overview

Next topic

6.3. TCP Transport

This Page

6.2. Libraries

6.2.1. Java

A messaging client library for Java is provided in the messaging.jar library. You can use the ClientConnection class to create a Messenger instance. You call connect with the name that the GUI should take on the messaging network, the hostname to make a TCP connection to and the port to connect on. If you can connect directly to a control node, this is your simplest option. below.

Most users will require stepping through a proxy host (users) to connect to a control node. It is recommended to use JSch to make an SSH connection and its ability to create standard SSH tunnels to form a path to the control node.

/* make a connection and then join a particular group */
ClientConnection messenger = new ClientConnection();
messenger.connect(name, host, port);
messenger.join("SomeTrafficGroup");

/* get the next message received, waiting if necessary */
MAGIMessage msg = messenger.nextMessage(true, 0);

/* Create a new message and send it */
MAGIMessage msg = new MAGIMessage();
msg.addGroup("Group1");
msg.addDock("wget");
msg.setData(Messenger.CONTENT_YAML, someserializeddata);
messenger.send(msg, DeliveryRequest.Acknowledgement());

6.2.2. Python

The python library contains messaging code for both simple TCP connections for a remote client as well as the other transports used in MAGI. This library is the base for the MAGI daemons on each node in the experiment.

For a remote client written in python, connecting to the experiment network can be done as so:

from magi.messaging import api

# Create the connection
messaging = api.ClientConnection(nodename, host, port)

# Receive the next message, waiting if necessary
msg = messaging.nextMessage(True)

# Create a message and send it
msg = api.MAGIMessage(nodes="N1", docks="wget", contenttype=api.MAGIMessage.YAML, data=encodeddata)
messaging.send(msg, api.Delivery.ACKNOWLEDGE)

There is currently no python support code for creating SSH tunnels or connecting to the Emulab XMLRPC server.